Last active
April 1, 2020 02:59
-
-
Save omar-3/43b857281832033e2114fd12c611558a to your computer and use it in GitHub Desktop.
implementation of toolz's pipe method in Chapel
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
proc notAdd(a: int, b: int) { | |
return (a + b , a + b); | |
} | |
proc notMul(a: int, b: int) { | |
return (a*b , a*b); | |
} | |
var h = [notAdd, notMul, notAdd, notMul, notAdd]; | |
var data = (1,2); | |
proc pipe(in data, functionArray){ | |
for func in functionArray { | |
data = func((...data)); | |
} | |
return data; | |
} | |
writeln(pipe(data, h)); | |
// how partial would be used here? imagine having "real" addition and multiplication functions and each function takes a tuple of values | |
// and return only one value. To make a pipeline of these functions, you can't have that behavior of having different number of argument | |
// on the input and output arguments in a pipeline, so to keep this pipeline intact, we could use partial to make the functions in the pipeline | |
// stream to have one default argument and just send one argument through that pipeline | |
// check that https://stackoverflow.com/a/15331967/7644243 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment