Skip to content

Instantly share code, notes, and snippets.

@RadoslawB
Last active March 24, 2020 01:06
Show Gist options
  • Save RadoslawB/67e85d20e7590632baa3905ba1c14e96 to your computer and use it in GitHub Desktop.
Save RadoslawB/67e85d20e7590632baa3905ba1c14e96 to your computer and use it in GitHub Desktop.
Python pipe higher-order function
from functools import reduce
def pipe(*functions):
return lambda x: reduce(lambda previous, next_: next_(previous), functions, x)
def compose(*functions):
return lambda x: reduce(lambda previous, next_: next_(previous), reversed(functions), x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment