Project

General

Profile

Actions

Feature #9071

closed

Enumerable#slice_after

Added by sawa (Tsuyoshi Sawada) almost 11 years ago. Updated about 6 years ago.

Status:
Closed
Target version:
-
[ruby-core:58123]

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

slice_after.patch (7.01 KB) slice_after.patch akr (Akira Tanaka), 05/10/2014 11:34 AM
slice_after2.patch (6.87 KB) slice_after2.patch akr (Akira Tanaka), 05/12/2014 09:46 AM

Updated by akr (Akira Tanaka) almost 11 years ago

2013/11/2 sawa (Tsuyoshi Sawada) :

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 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.

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

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

I updated the patch to simplify argument handling.

Actions #5

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]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0