Can I get this syntax to work using zip?

The obvious way to write it with zip doesn’t in fact return a tuple, because zip doesn’t. You could fix it by defining your own one. Or by just using the fact that map works like zip on multiple arguments:

julia> map(zip((1.0, 2.0), (3.0, 5.0))) do (i,j)
         diff = i - j
       end
2-element Vector{Float64}:
 -2.0
 -3.0

julia> _zip(ts::Tuple...) = ntuple(i -> map(t -> t[i], ts), minimum(length, ts));

julia> map(_zip((1.0, 2.0), (3.0, 5.0))) do (i,j)
          i - j  # diff
       end
(-2.0, -3.0)

julia> map((1.0, 2.0), (3.0, 5.0)) do i,j
         i - j
       end
(-2.0, -3.0)
4 Likes