Last active
March 24, 2020 01:06
-
-
Save RadoslawB/67e85d20e7590632baa3905ba1c14e96 to your computer and use it in GitHub Desktop.
Python pipe higher-order function
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 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