有没有函数解构

既然我可以这样

(x,y) = [1,1]

那么为什么不可以把这个解构放到函数上,像这样

function foo([x,y])
#code
end
foo([1,1]) #Error here

但是这是错误的,求解

Tuple 能直接解构,array 都手动解构了再传进去,也就是用变参函数。

julia> f((a,b)) = print("$a | $b")
f (generic function with 1 method)

julia> f((1,2))
1 | 2

julia> f(a, b...) = print("$a | $b")
f (generic function with 2 methods)

julia> f([1 2 3]...)
1 | (2, 3)