How to do "((1,2), 3) .+ ((1,2), 3)"?

If you’re doing math with tuples, consider using the StaticArrays packages instead. It gives you immutable arrays with arithmetic and linear algebra defined on them.

That said:

_f(x, y) = x + y
_f(x::Tuple, y::Tuple) = _f.(x, y)
julia> t1 = ((1,2), (3, (5,6)), (7, 8), 9);

julia> _f(t1, t1)
((2, 4), (6, (10, 12)), (14, 16), 18)

For numbers and Tuples of numbers, the above will work. Use at your own risk!

3 Likes