Giter Site home page Giter Site logo

tipe's Introduction

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

tipe's People

Contributors

dependabot[bot] avatar mishankov avatar

Stargazers

Andrew J Bonham avatar

Watchers

 avatar

tipe's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.