Julia makes it very easy to map/broadcast a function over a collection of argument tuples. But I don’t think it makes it so easy to map/broadcast multiple functions over one tuple of arguments.
We can do this:
f.((1, 2, 3)) == (f(1), f(2), f(3))
Is there a way to do this?
(f, g, h).(1) == (f(1), g(1), h(1))
Obviously this syntax can’t be made to work; it errors with MethodError: objects of type Tuple{...} are not callable. But there should be some “apply” function (or is there, and I just can’t find it). Something like this would make sense to me:
Although apply or funcall are not as useful in Julia as in some lisps, I sometimes miss them.
An example (completely different from the OP) is that I sometimes wish we could write function barriers like so:
arr = Any[1, 2, 3] # elements of type unknown to the compiler
apply(arr[1]) do x
# This anonymous function will get compiled & specialized for typeof(x)
for _ in 1:1_000_000
do_something_with(x)
end
end
I’d support this being in Base. In fact I find this a more natural (if a tiny bit more verbose) syntax for function calling than parentheses. I think it already meshes well with the rest of Julia. Broadcasting currently looks like f.([1,2,3]) or map(f, [1,2,3]) (not quite the same as broadcasting, but sometimes equivalent). In comparison,
The relationship between args |> f (left associative) and f <| args (right associative) is intuitive.
If you know about both + and <|, then it’s easy to extrapolate from [a,b,c] .+ [1,2,3], to [f,g,h] .<| [1,2,3], and then to [f g h] .<| [1,2,3] (for a matrix of all pairs).
There would be a uniform syntax for choosing the direction (LTR or RTL) in which function calls are written.