julia> pairzip(t::Tuple{}, u::Tuple{}) = ()
pairzip (generic function with 1 method)
julia> pairzip(t::Tuple{}, u::Tuple) = throw(ArgumentError("args must be equal length"))
pairzip (generic function with 2 methods)
julia> pairzip(t::Tuple, u::Tuple) = (t[1] => u[1], pairzip(Base.tail(t), Base.tail(u))...)
pairzip (generic function with 3 methods)
julia> pairzip((1, 2), (3, 4))
(1=>3, 2=>4)
julia> @code_warntype pairzip((1, 2), (3, 4))
Variables:
#self#::#pairzip
t::Tuple{Int64,Int64}
u::Tuple{Int64,Int64}
Body:
begin
return (Core.tuple)($(Expr(:new, Pair{Int64,Int64}, :((Base.getfield)(t, 1)::Int64), :((Base.getfield)(u, 1)::Int64))), $(Expr(:new, Pair{Int64,Int64}, :((Core.getfield)(t, 2)::Int64), :((Core.getfield)(u, 2)::Int64))))::Tuple{Pair{Int64,Int64},Pair{Int64,Int64}}
end::Tuple{Pair{Int64,Int64},Pair{Int64,Int64}}
julia> @code_warntype pairzip((1, :x, r"x"), ("w", 1.0, +))
Variables:
#self#::#pairzip
t::Tuple{Int64,Symbol,Regex}
u::Tuple{String,Float64,Base.#+}
Body:
begin
SSAValue(1) = (Core.getfield)(t::Tuple{Int64,Symbol,Regex}, 2)::Symbol
SSAValue(2) = (Core.getfield)(t::Tuple{Int64,Symbol,Regex}, 3)::Regex
return (Core.tuple)($(Expr(:new, Pair{Int64,String}, :((Base.getfield)(t, 1)::Int64), :((Base.getfield)(u, 1)::String))), $(Expr(:new, Pair{Symbol,Float64}, SSAValue(1), :((Core.getfield)(u, 2)::Float64))), $(Expr(:new, Pair{Regex,Base.#+}, SSAValue(2), :($(QuoteNode(+))))))::Tuple{Pair{Int64,String},Pair{Symbol,Float64},Pair{Regex,Base.#+}}
end::Tuple{Pair{Int64,String},Pair{Symbol,Float64},Pair{Regex,Base.#+}}
Here’s my solution, using 3 methods.