pydu/docs/functional.rst

23 lines
534 B
ReStructuredText
Raw Normal View History

2018-02-10 16:08:47 +00:00
Functional
----------
2018-03-10 05:12:01 +00:00
Utils for functional programming.
2018-02-10 16:08:47 +00:00
.. py:function:: pydu.functional.compose(*funcs)
Compose all functions. The previous function must accept one argument,
which is the output of the next function. The last function can accept
2018-02-19 05:33:43 +00:00
any args and kwargs.
compose(f1, f2, f3)(\*x) is same to f1(f2(f3(\*x))).
2018-02-10 16:08:47 +00:00
>>> from pydu.functional import compose
>>> def f1(a):
... return a+1
...
>>> def f2(a, b=2):
... return a+b
...
>>> compose(f1, f2)(1, b=3)
5