Sometimes I need to transform functions that take multiple arguments into one which takes a tuple. Eg g
does this below:
julia> g(f) = x->f(x...)
g (generic function with 1 method)
julia> f(a,b,c) = a + b + c
f (generic function with 1 method)
julia> g(f)((1,2,3))
6
I am wondering if g
already has a name, either in Base
or a library, or a more compact syntax. I am hesitant to name it and put it in a library
Also, with named tuples approaching, it has a sibling
h(f) = x->f(; x...)
that does the same for named tuples.
Why not use splatting at the call site instead? f((1,2,3)...)
I need to use it in a situation where I am given a function, and then need to provide a function as an argument somewher else. When I am controlling the call syntax, your solution of course works, but let’s suppose I don’t.
Alright, then a closure seems like it makes sense. Although I would not name it, just send in x->f(x...)
directly, since that is self documenting. I don’t think this needs to be in either Base or a library since it is one of the uncountable trivial transformation that you can do with a closure.
2 Likes