Skip to content

Commit 9ac2c0b

Browse files
unzip: return tuple of vectors
1 parent 9e81003 commit 9ac2c0b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

base/iterators.jl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ reverse(z::Zip) = Zip(map(reverse, z.is))
395395
# unzip
396396

397397
"""
398-
unzip(itrs) -> Vector{<:Vector}
398+
unzip(itrs) -> NTuple{length(first(itrs)), Vector}
399399
400-
The `unzip` function takes an iterator of iterators and returns a vector of
400+
The `unzip` function takes an iterator of iterators and returns a tuple of
401401
vectors such that the first vector contains the first element yielded by each
402402
iterator, the second vector the second element yielded by each iterator, etc.
403403
`unzip` is sort of an inverse to the `zip` operation, as the name suggests.
@@ -419,14 +419,10 @@ associated with iteration because it is the inverse of `zip`.
419419
420420
```jldoctest
421421
julia> unzip(enumerate("Hello"))
422-
2-element Array{Array{T,1} where T,1}:
423-
[1, 2, 3]
424-
['a', 'b', 'c']
425-
426-
julia> unzip([[1, 'a'], [2.5, 'z'], [0, 'x']])
427-
2-element Array{Array{T,1} where T,1}:
428-
Real[1, 2.5, 0]
429-
['a', 'z', 'x']
422+
([1, 2, 3, 4, 5], ['H', 'e', 'l', 'l', 'o'])
423+
424+
julia> unzip([[1, "apple"], [2.5, "orange"], [0, "mango"]])
425+
(Real[1, 2.5, 0], ["apple", "orange", "mango"])
430426
```
431427
"""
432428
function unzip(itrs)
@@ -451,7 +447,7 @@ function unzip(itrs)
451447
length(first(vecs)) == length(last(vecs)) ||
452448
throw(ArgumentError("unzip called with uneven iterators"))
453449
end
454-
return vecs
450+
return Tuple(vecs)
455451
end
456452

457453
# filter

0 commit comments

Comments
 (0)