Project

General

Profile

Feature #9071

Enumerable#slice_after

Added by Tsuyoshi Sawada about 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
[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.

slice_after.patch View (7.01 KB) Akira Tanaka, 05/10/2014 11:34 AM

slice_after2.patch View (6.87 KB) Akira Tanaka, 05/12/2014 09:46 AM

Associated revisions

Revision 45981
Added by Akira Tanaka over 2 years ago

  • enum.c: Enumerable#slice_after implemented.

  • enumerator.c: Enumerator::Lazy#slice_after implemented.

Requested by Tsuyoshi Sawada. [Feature #9071]

Revision 45981
Added by Akira Tanaka over 2 years ago

  • enum.c: Enumerable#slice_after implemented.

  • enumerator.c: Enumerator::Lazy#slice_after implemented.

Requested by Tsuyoshi Sawada. [Feature #9071]

Revision 45981
Added by Akira Tanaka over 2 years ago

  • enum.c: Enumerable#slice_after implemented.

  • enumerator.c: Enumerator::Lazy#slice_after implemented.

Requested by Tsuyoshi Sawada. [Feature #9071]

History

#1 [ruby-core:58133] Updated by Akira Tanaka about 3 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 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

#2 [ruby-core:62498] Updated by Akira Tanaka over 2 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?

#3 [ruby-core:62539] Updated by Akira Tanaka over 2 years ago

I updated the patch to simplify argument handling.

#4 [ruby-core:62635] Updated by Yukihiro Matsumoto over 2 years ago

Accepted.

Matz

#5 Updated by Akira Tanaka over 2 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. [Feature #9071]

Also available in: Atom PDF