Functional Utilities
Helper functions for functional composition and currying.
fpstreams.functional
curry(func)
Transforms a function that takes multiple arguments into a chain of functions. @curry def add(a, b): return a + b
add(1)(2) # returns 3
Source code in fpstreams\functional.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
pipe(value, *functions)
Passes a value through a sequence of functions. pipe(x, f, g, h) is equivalent to h(g(f(x)))
Source code in fpstreams\functional.py
9 10 11 12 13 14 | |
retry(attempts=3, backoff=1.5, jitter=True, exceptions=(Exception,))
Decorator to retry an async function upon failure.
Usage
@retry(attempts=3, backoff=2.0) async def fetch(url): ...
Or inline in a stream:
stream.map_async(retry(attempts=3)(fetch_func))
Source code in fpstreams\functional.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |