Created
January 16, 2013 01:40
Revisions
-
rossdylan created this gist
Jan 16, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ """ Misc tools/functions written by Ross Delinger """ def assemblePipeLine(*args, **kwargs): """ Given an arbitrary number of functions we create a pipeline where the output is piped between functions. you can also specify a tuple of arguments that should be passed to functions in the pipeline. The first arg is always the output of the previous function. """ def wrapper(*data): if len(args) == 1: if args[-1].__name__ in kwargs: otherArgs = data + kwargs[args[-1].__name__] return args[-1](*otherArgs) else: return args[-1](*data) else: if args[-1].__name__ in kwargs: otherArgs = kwargs[args[-1].__name__] del kwargs[args[-1].__name__] return args[-1](assemblePipeLine(*args[:-1], **kwargs)(*data), *otherArgs) else: return args[-1](assemblePipeLine(*args[:-1], **kwargs)(*data)) return wrapper def testAssemblePipelineWithArgs(): def add1(input_): return input_ + 1 def subX(input_, x): return input_ - x def stringify(input_): return str(input_) pipeline = assemblePipeLine( add1, subX, stringify, subX=(2,), ) print pipeline(10)