Created
January 5, 2016 02:58
-
-
Save thetrav/24e9a7307417d839242f to your computer and use it in GitHub Desktop.
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 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