Last active
February 18, 2020 05:18
-
-
Save marskar/28e1840e4215dcebecdc0aad2bd2af75 to your computer and use it in GitHub Desktop.
This file contains 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 pipe(data, *steps): | |
for step in steps: | |
if callable(step): | |
data = step(data) | |
elif hasattr(type(step), "__iter__"): | |
func, *others = step | |
for arg in others: | |
if not isinstance(arg, dict): | |
func = partial(func, arg) | |
else: | |
func = partial(func, **arg) | |
data = func(data) | |
return data | |
pipe( | |
"abc", | |
list, | |
[sorted, dict(reverse=True)], | |
" ".join, | |
lambda x: x.split() | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment