Last active
May 26, 2018 18:01
-
-
Save punnie/09cd2ae9c5a60ea81bd5f2e6b8ff2bf9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial | |
def step(original): | |
def wrapper(*args, **kwargs): | |
return partial(original, *args, **kwargs) | |
return wrapper | |
def pipe(initial, *fns): | |
carry = initial | |
for fn in fns: | |
carry = fn(carry) | |
return carry | |
@step | |
def fn1(i: int): | |
return i + 1 | |
@step | |
def fn2(i: int): | |
return i * 2 | |
@step | |
def fn3(i: int): | |
return i ** 2 | |
@step | |
def fn4(i: int, n: int = 1): | |
return i * n | |
pipe( | |
70, | |
fn1(), | |
fn4(n=10), | |
fn4(n=3), | |
fn3(), | |
) # 4536900 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment