-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Add eachrsplit iterator #51646
Conversation
7967578
to
0ea52a5
Compare
Unlike rsplit, this iterator returns split substrings right to left, but other- wise it behaves just like eachsplit. This design has been chosen to avoid either a costly double traversal of the input string, or needing a stack to store the strings. Both of these workarounds would lessen the appeal compared to simply using rsplit.
0ea52a5
to
fadedcb
Compare
Squashed, otherwise unchanged. I think the ASAN build failure is unrelated to this PR. |
Is there a reason why this wasn't implemented as an |
IIRC, this isn't just |
I see. So we could implement something like: function Iterators.reverse(itr::Union{SplitIterator,RSplitIterator})
itr.limit <= 0 || throw(ArgumentError("reverse does not support split iterators with limit = $(itr.limit) > 0"))
return (itr isa SplitIterator ? RSplitIterator : SplitIterator)(itr.str, itr.splitter, itr.limit, itr.keepempty)
end |
No, even then it is not the same, here's another counter-example:
|
Unlike rsplit, this iterator returns split substrings right to left, but other- wise it behaves just like eachsplit.
This design has been chosen to avoid either a costly double traversal of the input string, or needing a stack to store the strings. Both of these workarounds would lessen the appeal compared to simply using rsplit.
Closes #45385
Request for comments
rsplit
? I believe this is unfortunately necessary.