Feature #9071
closedEnumerable#slice_after
Description
I see in this discussion: http://ruby.11.x6.nabble.com/ruby-dev-38392-Enumerable-gather-each-td3534746.html that Enumerable#slice_before
was named as such, having in mind the possibility of Enumerable#slice_after
being implemented in the future. I feel the former convenient, but believe the latter should be as well, and am wondering why the latter was not implemented at the same time. I request it to be implemented.
Files
Updated by akr (Akira Tanaka) almost 11 years ago
2013/11/2 sawa (Tsuyoshi Sawada) sawadatsuyoshi@gmail.com:
Feature #9071: Enumerable#slice_after
https://bugs.ruby-lang.org/issues/9071
I see in this discussion: http://ruby.11.x6.nabble.com/ruby-dev-38392-Enumerable-gather-each-td3534746.html that
Enumerable#slice_before
was named as such, having in mind the possibility ofEnumerable#slice_after
being implemented in the future. I feel the former convenient, but believe the latter should be as well, and am wondering why the latter was not implemented at the same time. I request it to be implemented.
The main reason is no one requested.
I have not enough time to implement it now.
If you'll implement Enumerable#slice_after
, I recommend not implement
state management
(the 3rd form of Enumerable#slice_before
:
enum.slice_before(initial_state) { |elt, state| bool }
).
Now, I think state management should be separated to another method as
http://bugs.ruby-lang.org/issues/8840#note-5
Tanaka Akira
Updated by akr (Akira Tanaka) over 10 years ago
- File slice_after.patch slice_after.patch added
- Assignee set to akr (Akira Tanaka)
I implemented Enumerable#slice_after
.
I found two request for this feature:
This issue and
http://stackoverflow.com/questions/22622156/how-to-implement-slice-after-or-group-certain-elements-with-certain-subsequent
I wrote the document with an example follows:
% ./ruby -e '
lines = ["foo\n", "bar\\\n", "baz\n", "\n", "qux\n"]
e = lines.slice_after(/(?<!\\)\n\z/)
p e.to_a
p e.map {|ll| ll[0...-1].map {|l| l.sub(/\\\n\z/, "") }.join + ll.last }'
[["foo\n"], ["bar\\\n", "baz\n"], ["\n"], ["qux\n"]]
["foo\n", "barbaz\n", "\n", "qux\n"]
This concatenates continuation lines.
More useful (catchy) examples may be helpful to persuade matz.
Any idea?
Updated by akr (Akira Tanaka) over 10 years ago
- File slice_after2.patch slice_after2.patch added
I updated the patch to simplify argument handling.
Updated by matz (Yukihiro Matsumoto) over 10 years ago
Accepted.
Matz
Updated by akr (Akira Tanaka) over 10 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Applied in changeset r45981.
-
enum.c: Enumerable#slice_after implemented.
-
enumerator.c: Enumerator::Lazy#slice_after implemented.
Requested by Tsuyoshi Sawada. [ruby-core:58123] [Feature #9071]