Skip to main content

Typed pipe

Project description

PyPI

Tipe - typed pipe

Tipe allows you to create constructions similar to pipe operator, where result of a function used as an input of next function

Instalation

pip install tipe

Examples

>>> from tipe import Pipe
>>> 
>>> Pipe(2).pipe(lambda x: x + 1).pipe(float).unwrap()
3.0
>>> Pipe([2, 3, 4]) \
...         .pipe(len) \
...         .pipe(lambda x: x + 1) \
...         .pipe(float) \
...         .unwrap()
4.0
>>> Pipe(2).pipe(range, 4).pipe(len).unwrap()
2

Equivalent for examples above would be

>>> float(2+1)
3.0
>>> float(len([2, 3, 4]) + 1)
4.0
>>> len(range(2, 4))
2

API

Pipe()

To use .pipe() on a value wrap it with Pipe class

>>> Pipe(2)
Pipe(2)

Pipe.pipe()

Pass function to execute on Pipe value and additional params for it. Wraps function result in Pipe and returns it

Pipe.check()

Like Pipe.pipe() but does not change the value inside Pipe. May be useful for debugging purposes

>>> Pipe(2).pipe(lambda x: x ** x).check(print).pipe(float).unwrap()
4
4.0

Pipe.unwrap()

Returns value from Pipe

Short forms

For convenience you can use P as short version of Pipe and short versions of the methods:

  • p: pipe
  • c: check
  • u: unwrap

Types

tipe tries its best to stay typesafe, so every function knows what exactly what it returns as long as it is inferable from arguments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tipe-1.1.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

tipe-1.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file tipe-1.1.0.tar.gz.

File metadata

  • Download URL: tipe-1.1.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.2.0-1019-azure

File hashes

Hashes for tipe-1.1.0.tar.gz
Algorithm Hash digest
SHA256 040277478f9c953dd77709f6b7b99effb1b456e5594ba9651f42442bc4d05a4d
MD5 dec7c4a948661b8e4adf881ba8f3162d
BLAKE2b-256 6ca3df3f34a38532afb8fc40e5a17a5c3104b2676a9bae7de1e8679d9b1c6246

See more details on using hashes here.

File details

Details for the file tipe-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tipe-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.2.0-1019-azure

File hashes

Hashes for tipe-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40763195c7864abbbb47209e122ccb4c8c175f9934fbebadf26b1f516c7823e5
MD5 f1e3049a7fa44869e3984a1ced6addb6
BLAKE2b-256 9b770b3a12f960c2fd40935a7be1abfd13f43ef4faa600a4b2a31b9360abc137

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page