Skip to content

eltype inference for Iterators.map could be more precise #56891

@ehehela

Description

@ehehela

I am puzzled on why eltype does not infer more precisely for Iterators.map(f, iterators...), especially when both the eltype of the input iterators and the return type of f seem to be inferable.
Would it be possible to improve the eltype inference for Iterators.

julia> fun(x) = x^2
fun (generic function with 1 method)

julia> a = Iterators.map(fun, 1:3)
Base.Generator{UnitRange{Int64}, typeof(fun)}(fun, 1:3)

julia> eltype(a)
Any    # Expected: Int

This enhancement could help improve type stability and make Iterators.map more consistent with the inferred types of other Julia constructs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    collectionsData structures holding multiple items, e.g. setsinvalidIndicates that an issue or pull request is no longer relevantiterationInvolves iteration or the iteration protocol

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions