Skip to content

Instantly share code, notes, and snippets.

@punnie
Last active May 26, 2018 18:01
Show Gist options
  • Save punnie/09cd2ae9c5a60ea81bd5f2e6b8ff2bf9 to your computer and use it in GitHub Desktop.
Save punnie/09cd2ae9c5a60ea81bd5f2e6b8ff2bf9 to your computer and use it in GitHub Desktop.
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