Last active
March 18, 2021 19:02
-
-
Save kamikat/5607645 to your computer and use it in GitHub Desktop.
a simple demo of pipeline pattern for python
This file contains 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
def processor1(obj): | |
"""Require: text; yield firstchar""" | |
obj['firstchar'] = obj.text[:1] | |
return obj | |
def processor2(obj): | |
"""Require: firstchar, text2; yield concat""" | |
obj['concat'] = obj.firstchar + obj.text2 | |
return obj | |
procs = [ | |
processor1, | |
processor2 | |
] | |
obj = { | |
text: "Kr", | |
text2: " 233..." | |
} | |
for proc in procs: | |
proc(obj) | |
print obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But... in the Pipeline Pattern the input of one process is the output of another. Am I wrong?
Btw, thanks for sharing!