Skip to content

Instantly share code, notes, and snippets.

@helpermethod
Last active March 11, 2020 11:37
Show Gist options
  • Save helpermethod/6a467d5b91b542ab367d3b519ace6cee to your computer and use it in GitHub Desktop.
Save helpermethod/6a467d5b91b542ab367d3b519ace6cee to your computer and use it in GitHub Desktop.
A pipe function in 7 lines of Groovy
def pipe(fn, ...fns) {
return {
fns.inject(fn(it)) { acc, value ->
value(acc)
}
}
}
@voorth
Copy link

voorth commented Oct 1, 2019

Interesting - but what does the prefix '...' do? I can't seem to find it in the Groovy documentation..

@helpermethod
Copy link
Author

@voorth It's a varargs parameter without the type :). The function signature with types

def pipe(Closure fn, Closure... fns)

@voorth
Copy link

voorth commented Oct 1, 2019

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