-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
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 This is distinct from an rsplit
method that outputs a type-stable tuple.)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.