@@ -12,7 +12,7 @@ using .Base:
12
12
@inline , Pair, AbstractDict, IndexLinear, IndexCartesian, IndexStyle, AbstractVector, Vector,
13
13
tail, tuple_type_head, tuple_type_tail, tuple_type_cons, SizeUnknown, HasLength, HasShape,
14
14
IsInfinite, EltypeUnknown, HasEltype, OneTo, @propagate_inbounds , Generator, AbstractRange,
15
- LinearIndices, (:), | , + , - , != = , ! , <= , < , missing , map, any, @boundscheck , @inbounds
15
+ LinearIndices, (:), | , + , - , != = , ! , <= , < , missing , any, @boundscheck , @inbounds
16
16
17
17
import . Base:
18
18
first, last,
@@ -24,6 +24,26 @@ import .Base:
24
24
25
25
export enumerate, zip, rest, countfrom, take, drop, takewhile, dropwhile, cycle, repeated, product, flatten, partition
26
26
27
+ """
28
+ Iterators.map(f, iterators...)
29
+
30
+ Create a lazy mapping. This is another syntax for writing
31
+ `(f(args...) for args in zip(iterators...))`.
32
+
33
+ !!! compat "Julia 1.6"
34
+ This function requires at least Julia 1.6.
35
+
36
+ # Examples
37
+ ```jldoctest
38
+ julia> collect(Iterators.map(x -> x^2, 1:3))
39
+ 3-element Array{Int64,1}:
40
+ 1
41
+ 4
42
+ 9
43
+ ```
44
+ """
45
+ map (f, args... ) = Base. Generator (f, args... )
46
+
27
47
tail_if_any (:: Tuple{} ) = ()
28
48
tail_if_any (x:: Tuple ) = tail (x)
29
49
@@ -322,17 +342,17 @@ eltype(::Type{Zip{Is}}) where {Is<:Tuple} = _zip_eltype(Is)
322
342
_zip_eltype (:: Type{Is} ) where {Is<: Tuple } =
323
343
tuple_type_cons (eltype (tuple_type_head (Is)), _zip_eltype (tuple_type_tail (Is)))
324
344
_zip_eltype (:: Type{Tuple{}} ) = Tuple{}
325
- @inline isdone (z:: Zip ) = _zip_any_isdone (z. is, map (_ -> (), z. is))
326
- @inline isdone (z:: Zip , ss) = _zip_any_isdone (z. is, map (tuple, ss))
345
+ @inline isdone (z:: Zip ) = _zip_any_isdone (z. is, Base . map (_ -> (), z. is))
346
+ @inline isdone (z:: Zip , ss) = _zip_any_isdone (z. is, Base . map (tuple, ss))
327
347
@inline function _zip_any_isdone (is, ss)
328
348
d1 = isdone (is[1 ], ss[1 ]. .. )
329
349
d1 === true && return true
330
350
return d1 | _zip_any_isdone (tail (is), tail (ss))
331
351
end
332
352
@inline _zip_any_isdone (:: Tuple{} , :: Tuple{} ) = false
333
353
334
- @propagate_inbounds iterate (z:: Zip ) = _zip_iterate_all (z. is, map (_ -> (), z. is))
335
- @propagate_inbounds iterate (z:: Zip , ss) = _zip_iterate_all (z. is, map (tuple, ss))
354
+ @propagate_inbounds iterate (z:: Zip ) = _zip_iterate_all (z. is, Base . map (_ -> (), z. is))
355
+ @propagate_inbounds iterate (z:: Zip , ss) = _zip_iterate_all (z. is, Base . map (tuple, ss))
336
356
337
357
# This first queries isdone from every iterator. If any gives true, it immediately returns
338
358
# nothing. It then iterates all those where isdone returned missing, afterwards all those
@@ -388,7 +408,7 @@ _zip_iterator_eltype(::Type{Is}) where {Is<:Tuple} =
388
408
_zip_iterator_eltype (tuple_type_tail (Is)))
389
409
_zip_iterator_eltype (:: Type{Tuple{}} ) = HasEltype ()
390
410
391
- reverse (z:: Zip ) = Zip (map (reverse, z. is))
411
+ reverse (z:: Zip ) = Zip (Base . map (reverse, z. is))
392
412
393
413
# filter
394
414
982
1002
isdone (P) === true && return nothing
983
1003
next = _piterate (P. iterators... )
984
1004
next === nothing && return nothing
985
- return (map (x -> x[1 ], next), next)
1005
+ return (Base . map (x -> x[1 ], next), next)
986
1006
end
987
1007
988
1008
@inline _piterate1 (:: Tuple{} , :: Tuple{} ) = nothing
@@ -1003,10 +1023,10 @@ end
1003
1023
isdone (P, states) === true && return nothing
1004
1024
next = _piterate1 (P. iterators, states)
1005
1025
next === nothing && return nothing
1006
- return (map (x -> x[1 ], next), next)
1026
+ return (Base . map (x -> x[1 ], next), next)
1007
1027
end
1008
1028
1009
- reverse (p:: ProductIterator ) = ProductIterator (map (reverse, p. iterators))
1029
+ reverse (p:: ProductIterator ) = ProductIterator (Base . map (reverse, p. iterators))
1010
1030
1011
1031
# flatten an iterator of iterators
1012
1032
0 commit comments