Skip to content

Instantly share code, notes, and snippets.

@attomos
Forked from kamikat/pipeline_pattern.py
Created March 26, 2020 13:34
Show Gist options
  • Save attomos/b9df86768dac58dea9fb7513924baafc to your computer and use it in GitHub Desktop.
Save attomos/b9df86768dac58dea9fb7513924baafc to your computer and use it in GitHub Desktop.
a simple demo of pipeline pattern for python
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