Python data model in action - pipe with toolz

by zero323
GNU/Linux â—† xterm-256color â—† zsh 463 views

And before you ask, any curried function can be used this way, so a subset of toolz.curried

>>> from toolz.curried import take, take_nth, sliding_window
>>> range(100) >> take_nth(11) >> sliding_window(3) >> take(3) >> curry(list)
[(0, 11, 22), (11, 22, 33), (22, 33, 44)]

or aribitrary annotated function

>>> @curry
... def to_lower(s):
...     if s is not None:
...         return s.lower()
>>> "FOO" >> to_lower()
'foo'
>>> @curry
... def append_text(s, text):
...     if s is not None:
...         return s + text
...     
...     
>>> 
>>> "FOO" >> to_lower() >> append_text(text="bar")
'foobar'

can be used this way.