Skip to content

Instantly share code, notes, and snippets.

@marskar
Last active February 18, 2020 05:18
Show Gist options
  • Save marskar/28e1840e4215dcebecdc0aad2bd2af75 to your computer and use it in GitHub Desktop.
Save marskar/28e1840e4215dcebecdc0aad2bd2af75 to your computer and use it in GitHub Desktop.
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