Repository: JuliaLang/julia
File: base/iterators.jl (Julia)

Code before:
const Base = parentmodule(@__MODULE__)
using .Base:
    @inline, Pair, Pairs, AbstractDict, IndexLinear, IndexStyle, AbstractVector, Vector,
    SizeUnknown, HasLength, HasShape, IsInfinite, EltypeUnknown, HasEltype, OneTo,
    @propagate_inbounds, @isdefined, @boundscheck, @inbounds, Generator, IdDict,
    AbstractRange, AbstractUnitRange, UnitRange, LinearIndices, TupleOrBottom,
    (:), |, +, -, *, !==, !, ==, !=, <=, <, >, >=, =>, missing,
    any, _counttuple, eachindex, ntuple, zero, prod, reduce, in, firstindex, lastindex,
    tail, fieldtypes, min, max, minimum, zero, oneunit, promote, promote_shape, LazyString,
    afoldl
using .Core
using Core: @doc

using Base:
    cld, fld, resize!, IndexCartesian, Checked
using .Checked: checked_mul

import Base:
    first, last,
    isempty, length, size, axes, ndims,
    eltype, IteratorSize, IteratorEltype, promote_typejoin,
    haskey, keys, values, pairs,
    getindex, setindex!, get, iterate,
    popfirst!, isdone, peek, intersect

export enumerate, zip, rest, countfrom, take, drop, takewhile, dropwhile, cycle, repeated, product, flatten, flatmap, partition, findall
public accumulate, filter, map, peel, reverse, Stateful

"""
    Iterators.map(f, iterators...)

Create a lazy mapping.  This is another syntax for writing
`(f(args...) for args in zip(iterators...))`.

!!! compat "Julia 1.6"
    This function requires at least Julia 1.6.

# Examples
```jldoctest
julia> collect(Iterators.map(x -> x^2, 1:3))
3-element Vector{Int64}:
 1
 4
 9
```
"""
map(f, arg, args...) = Base.Generator(f, arg, args...)

_min_length(a, b, ::IsInfinite, ::IsInfinite) = min(length(a),length(b)) # inherit behaviour, error
_min_length(a, b, A, ::IsInfinite) = length(a)
_min_length(a, b, ::IsInfinite, B) = length(b)

Review comment (suggestion):
All these exports are bad because they conflict with Base exports. There's no use (unless you use `baremodule`). Let's not add another export (make it public :) )

Code after:
const Base = parentmodule(@__MODULE__)
using .Base:
    @inline, Pair, Pairs, AbstractDict, IndexLinear, IndexStyle, AbstractVector, Vector,
    SizeUnknown, HasLength, HasShape, IsInfinite, EltypeUnknown, HasEltype, OneTo,
    @propagate_inbounds, @isdefined, @boundscheck, @inbounds, Generator, IdDict,
    AbstractRange, AbstractUnitRange, UnitRange, LinearIndices, TupleOrBottom,
    (:), |, +, -, *, !==, !, ==, !=, <=, <, >, >=, =>, missing,
    any, _counttuple, eachindex, ntuple, zero, prod, reduce, in, firstindex, lastindex,
    tail, fieldtypes, min, max, minimum, zero, oneunit, promote, promote_shape, LazyString,
    afoldl, mod1
using .Core
using Core: @doc

using Base:
    cld, fld, resize!, IndexCartesian, Checked
using .Checked: checked_mul

import Base:
    first, last,
    isempty, length, size, axes, ndims,
    eltype, IteratorSize, IteratorEltype, promote_typejoin,
    haskey, keys, values, pairs,
    getindex, setindex!, get, iterate,
    popfirst!, isdone, peek, intersect

export enumerate, zip, rest, countfrom, take, drop, takewhile, dropwhile, cycle, repeated, product, flatten, flatmap, partition, nth, findeach
public accumulate, filter, map, peel, reverse, Stateful

"""
    Iterators.map(f, iterators...)

Create a lazy mapping.  This is another syntax for writing
`(f(args...) for args in zip(iterators...))`.

!!! compat "Julia 1.6"
    This function requires at least Julia 1.6.

# Examples
```jldoctest
julia> collect(Iterators.map(x -> x^2, 1:3))
3-element Vector{Int64}:
 1
 4
 9
```
"""
map(f, arg, args...) = Base.Generator(f, arg, args...)

_min_length(a, b, ::IsInfinite, ::IsInfinite) = min(length(a),length(b)) # inherit behaviour, error
_min_length(a, b, A, ::IsInfinite) = length(a)
_min_length(a, b, ::IsInfinite, B) = length(b)