I was needing a way to concatenate an undefined number of tuples. I came up with
tuplejoin(t1::Tuple, t2::Tuple, t3...) = tuplejoin((t1..., t2...), t3...)
tuplejoin(t::Tuple) = t
This works
julia> tuplejoin((1,2),(3,4),(5,6))
(1, 2, 3, 4, 5, 6)
However, while it is fast for two or three tuples, the time it takes grows very fast with additional tuples
julia> using BenchmarkTools
julia> @btime tuplejoin((1,2),(1,2));
1.609 ns (0 allocations: 0 bytes)
julia> @btime tuplejoin((1,2),(1,2),(1,2));
6.962 ns (1 allocation: 64 bytes)
julia> @btime tuplejoin((1,2),(1,2),(1,2),(1,2));
277.876 ns (6 allocations: 320 bytes)
julia> @btime tuplejoin((1,2),(1,2),(1,2),(1,2),(1,2));
730.792 ns (11 allocations: 608 bytes)
julia> @btime tuplejoin((1,2),(1,2),(1,2),(1,2),(1,2),(1,2));
1.319 μs (17 allocations: 976 bytes)
Is there a better way to do this so it scales well with the number of tuples?