Last active
August 25, 2022 11:05
-
-
Save RahulDas-dev/5772b30e4a377be90288f93067975dba to your computer and use it in GitHub Desktop.
Simple Pipeline Patteren using reduce method
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 | |
# creates pipeline object from list of callables | |
def make_pipeline(list_of_callables): | |
return reduce(lambda f,g: lambda x: g(f(x)), list_of_callables) | |
add1 = lambda x: x+'1' # Oprtaion 1 | |
add2 = lambda x: x+'2' # Oprtaion 2 | |
add3 = lambda x: x+'3' # Oprtaion 3 | |
add4 = lambda x: x+'4' # Oprtaion 4 | |
# creating pipleline object to apply add1,add2,add3,add4 operations | |
# on inputdata | |
pipeline = make_pipeline([add1,add2,add3,add4]) | |
print(pipeline('hi')) #passing data to pipleline + printing | |
>> hi1234 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.