Skip to content

Instantly share code, notes, and snippets.

@thetrav
Created January 5, 2016 02:58
Show Gist options
  • Save thetrav/24e9a7307417d839242f to your computer and use it in GitHub Desktop.
Save thetrav/24e9a7307417d839242f to your computer and use it in GitHub Desktop.
def double(i):
return i*2
def increment(i):
if i=='broken':
return None
return i+1
def flatten(listOfOptions):
return reduce(list.__add__, listOfOptions)
def applyfn(input, fn):
value = map(fn, input)
if value == [None]:
return []
return value
def pipeline(functions, inputs):
def input(item):
return reduce(applyfn, functions, [item])
return flatten(map(input, inputs))
print("{}".format(pipeline([increment, double],[1,'broken',2])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment