@@ -395,9 +395,9 @@ reverse(z::Zip) = Zip(map(reverse, z.is))
395
395
# unzip
396
396
397
397
"""
398
- unzip(itrs) -> Vector{<: Vector}
398
+ unzip(itrs) -> NTuple{length(first(itrs)), Vector}
399
399
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
401
401
vectors such that the first vector contains the first element yielded by each
402
402
iterator, the second vector the second element yielded by each iterator, etc.
403
403
`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`.
419
419
420
420
```jldoctest
421
421
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"])
430
426
```
431
427
"""
432
428
function unzip (itrs)
@@ -451,7 +447,7 @@ function unzip(itrs)
451
447
length (first (vecs)) == length (last (vecs)) ||
452
448
throw (ArgumentError (" unzip called with uneven iterators" ))
453
449
end
454
- return vecs
450
+ return Tuple ( vecs)
455
451
end
456
452
457
453
# filter
0 commit comments