Skip to content

Commit

Permalink
unzip: return tuple of vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Oct 9, 2019
1 parent e9fd0c6 commit 8c8f717
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ reverse(z::Zip) = Zip(map(reverse, z.is))
# unzip

"""
unzip(itrs) -> Vector{<:Vector}
unzip(itrs) -> NTuple{length(first(itrs)), Vector}
The `unzip` function takes an iterator of iterators and returns a vector of
The `unzip` function takes an iterator of iterators and returns a tuple of
vectors such that the first vector contains the first element yielded by each
iterator, the second vector the second element yielded by each iterator, etc.
`unzip` is sort of an inverse to the `zip` operation, as the name suggests.
Expand All @@ -419,14 +419,10 @@ associated with iteration beacuse it is the inverse of `zip`.
```jldoctest
julia> unzip(enumerate("Hello"))
2-element Array{Array{T,1} where T,1}:
[1, 2, 3]
['a', 'b', 'c']
julia> unzip([[1, 'a'], [2.5, 'z'], [0, 'x']])
2-element Array{Array{T,1} where T,1}:
Real[1, 2.5, 0]
['a', 'z', 'x']
([1, 2, 3, 4, 5], ['H', 'e', 'l', 'l', 'o'])
julia> unzip([[1, "apple"], [2.5, "orange"], [0, "mango"]])
(Real[1, 2.5, 0], ["apple", "orange", "mango"])
```
"""
function unzip(itrs)
Expand All @@ -451,7 +447,7 @@ function unzip(itrs)
length(first(vecs)) == length(last(vecs)) ||
throw(ArgumentError("unzip called with uneven iterators"))
end
return vecs
return Tuple(vecs)
end

# filter
Expand Down

0 comments on commit 8c8f717

Please sign in to comment.