Hi, I have trouble understanding the bolded line following code from RecursiveArrayTools.jl.
struct ArrayPartition{T,S<:Tuple} <: AbstractVector{T}
x::S
end
## constructors
**ArrayPartition(x...) = ArrayPartition((x...,))**
function ArrayPartition(x::S, ::Type{Val{copy_x}}=Val{false}) where {S<:Tuple,copy_x}
T = promote_type(eltype.(x)...)
if copy_x
return ArrayPartition{T,S}(copy.(x))
else
return ArrayPartition{T,S}(x)
end
end
My understanding of the bolded line is that it allowed me to have as an input more than one object of type tuple e.g. ArrayPartition((1,2), (3,4)). What I don’t understand however is what is the function of the colon after x… on the RHS, ArrayPartition(x…) = ArrayPartition((x…,)). More specifically, I know that (x…,) is actually ((1,2),(3,4)) but I can understand how this syntax ArrayPartition((x…,)) produces such result.
Thank you for the reply, but just to make sure that I understand what you are saying correctly. In the example above I have x = [(1,2), (3,4)]. In the case of Tuple(x…), x… is in the context of a function call. Hence, x… separates x into individual args which are (1,2) and (3,4). Thus Tuple(x…) is the same as Tuple((1,2),(3,4)). What is a function type signature (is it just typeof( ))?
In my OP, I also try to understand the meaning of
ArrayPartition(x…) = ArrayPartition((x…,))
My understanding now is that ArrayPartition(x…) is just a new constructor for ArrayPartition, and the meaning of x… in this case depends how the constructor is defined.
Also your understanding of splat in a function call is correct.
by “in a function type signature” I meant when used on a function argument like f(x...) = x
sorry my descriptive terms still are a mess from Haskel and ruby and everything else, so my Julia has an accent…