Skip to content

reverse iteration for eachsplit #43740

@stevengj

Description

@stevengj

As commented in #39245 (comment), it would be nice to add iterate methods for Iterators.Reverse{SplitIterator} — in general, for any iterator where it is feasible to do so, we'd like to support reverse iteration, and this must be implemented in Base to avoid type piracy.

Currently, e.g. collect(Iterators.reverse(eachsplit("a.b.c", '.', limit=2))) gives a MethodError because it tries to fall back on the generic method that requires indexing.

(Would also be helpful in #43557, since it would give us an easy rsplit method that outputs a type-stable tuple.) This is distinct from an eachrsplit iterator.

Note that the case with a limit argument seems a bit tricky to implement, since it seems like you would first need to count all the delimiters in the string, an O(n) operation, in order to figure out how many delimiters to skip at the end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsiterationInvolves iteration or the iteration protocolstrings"Strings!"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions