Last active
March 11, 2020 11:37
-
-
Save helpermethod/6a467d5b91b542ab367d3b519ace6cee to your computer and use it in GitHub Desktop.
A pipe function in 7 lines of Groovy
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 pipe(fn, ...fns) { | |
return { | |
fns.inject(fn(it)) { acc, value -> | |
value(acc) | |
} | |
} | |
} |
@voorth It's a varargs parameter without the type :). The function signature with types
def pipe(Closure fn, Closure... fns)
Ah, clear, thanks! Another groovy feature that I wasn't previously aware of..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting - but what does the prefix '...' do? I can't seem to find it in the Groovy documentation..