Skip to content

Instantly share code, notes, and snippets.

@RahulDas-dev
Last active August 25, 2022 11:05
Show Gist options
  • Save RahulDas-dev/5772b30e4a377be90288f93067975dba to your computer and use it in GitHub Desktop.
Save RahulDas-dev/5772b30e4a377be90288f93067975dba to your computer and use it in GitHub Desktop.
Simple Pipeline Patteren using reduce method
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
@RahulDas-dev
Copy link
Author

RahulDas-dev commented Aug 25, 2022

pipeline py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment