Skip to content

keys(::Generator) for find* and arg* #34674

Closed
@rapus95

Description

@rapus95

Tl;Dr:
Add

Base.keys(gen::Base.Generator) = Base.keys(gen.iter)

to Base.


Partially related to my comment in #34368 (comment) regarding the support of traits on generators.
Currently there is no way to use find* on generators. Reason is that there is no keys function:

julia> findmax(abs(x-1) for x in [1,5,2,9])
ERROR: MethodError: no method matching keys(::Base.Generator{Array{Int64,1},var"#97#98"})

But since generators are said to be the lazy variant of map and map preserves the indices it would be good to define that missing keys method.

That would allow for some very generic findmax(iter) and argmax(iter) as arbitrary lazy maps are allowed while maintaining good performance and low memory footprint.

Edit: adding the missing find* and arg* with custom transform functions would be appreciated aswell to allow for the convenient do-block notation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions