# Collecting zip

**URL:** <https://discourse.julialang.org/t/collecting-zip/20739>\
**Category:** New to Julia\
**Created:** [February 13, 2019, 10:09am UTC](https://discourse.julialang.org/t/collecting-zip/20739 "2019-02-13T10:09:20Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 13, 2019, 11:02am UTC](https://discourse.julialang.org/t/collecting-zip/20739/2 "2019-02-13T11:02:08Z")

</div>

I think [this is the relevant issue](https://github.com/JuliaLang/julia/pull/29927), and it seems still unresolved.

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

```julia
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:

```julia
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
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')

```

---

_[View the full topic](https://discourse.julialang.org/t/collecting-zip/20739)._
