Collecting zip

I think this is the relevant issue, and it seems still unresolved.

The difference between the array and the string is that they have return different values for IteratorSize:

julia> Base.IteratorSize(["a", "b", "c"])
Base.HasShape{1}()

julia> Base.IteratorSize("abc")
Base.HasLength()

This suggests the following non-intrusive workaround for your case:

function zip_collect(itr)
    itrsize = Base.IteratorSize(itr)
    itrsize isa Base.HasShape && (itrsize = Base.HasLength())
    Base._collect(1:1, itr, Base.IteratorEltype(itr), itrsize)
end

With result:

julia> zip_collect(zip(1:5, ["a", "b", "c"]))
3-element Array{Tuple{Int64,String},1}:
 (1, "a")
 (2, "b")
 (3, "c")

julia> zip_collect(zip(1:5, "abc"))
3-element Array{Tuple{Int64,Char},1}:
 (1, 'a')
 (2, 'b')
 (3, 'c')
1 Like