Skip to content

Instantly share code, notes, and snippets.

@LIQRGV
Created January 9, 2020 02:22
Show Gist options
  • Save LIQRGV/366aeca5145e5c7641391d451b9225da to your computer and use it in GitHub Desktop.
Save LIQRGV/366aeca5145e5c7641391d451b9225da to your computer and use it in GitHub Desktop.
#As part of a data processing pipeline, complete the implementation of the pipeline method:
#The method should accept a variable number of functions, and it should return a new function that accepts one parameter arg.
#The returned function should call the first function in the pipeline with the parameter arg, and call the second function with the result of the first function.
#The returned function should continue calling each function in the pipeline in order, following the same pattern, and return the value from the last function.
#For example, pipeline(lambda x: x * 3, lambda x: x + 1, lambda x: x / 2) then calling the returned function with 3 should return 5.0.
#https://www.testdome.com/questions/python/pipeline/24245?visibility=1&skillId=9
def pipeline(*funcs):
def helper(arg):
result = arg
for f in funcs:
result = f(result)
return result
return helper
fun = pipeline(lambda x: x * 3, lambda x: x + 1, lambda x: x / 2)
print(fun(3)) #should print 5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment