Created
October 9, 2020 17:10
-
-
Save Rowadz/9e8eba9abdf0dacb0c9139624821e7ea to your computer and use it in GitHub Desktop.
A function in python that compose functions together
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 func01(name): return f'{name}-func01' | |
def func02(name): return f'{name}-func02' | |
def func03(name): return f'{name}-func03' | |
def func04(name): return f'{name}-func04' | |
def func05(name): return f'{name}-func05' | |
def compose(*funcs): | |
return lambda param: reduce( | |
lambda prev_val, curr_func: curr_func(prev_val), | |
reversed(funcs), | |
param | |
) | |
composed_func = compose(func01, func02, func03, func04, func05) | |
print(composed_func('rowadz')) | |
# rowadz-func05-func04-func03-func02-func01 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment