Forum: Ruby-core [ruby-trunk - Feature #9071][Open] Enumerable#slice_after

43421679c356f438c69bf6947e62c4ec?d=identicon&s=25 Tsuyoshi S. (tsuyoshi_s)
on 2013-11-01 17:22
(Received via mailing list)
Issue #9071 has been reported by sawa (Tsuyoshi Sawada).

----------------------------------------
Feature #9071: Enumerable#slice_after
https://bugs.ruby-lang.org/issues/9071

Author: sawa (Tsuyoshi Sawada)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


I see in this discussion:
http://ruby.11.x6.nabble.com/ruby-dev-38392-Enumer...
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.
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 Tanaka Akira (Guest)
on 2013-11-02 04:10
(Received via mailing list)
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-Enumer...
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 separeted to another method as
http://bugs.ruby-lang.org/issues/8840#note-5
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 unknown (Guest)
on 2014-05-10 13:35
(Received via mailing list)
Issue #9071 has been updated by Akira Tanaka.

File slice_after.patch added
Assignee set to Akira Tanaka

I impelemented Enumerable#slice_after.

I found two request for this feature:
This issue and
http://stackoverflow.com/questions/22622156/how-to...

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?


----------------------------------------
Feature #9071: Enumerable#slice_after
https://bugs.ruby-lang.org/issues/9071#change-46659

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: Akira Tanaka
* Category:
* Target version:
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 unknown (Guest)
on 2014-05-12 11:47
(Received via mailing list)
Issue #9071 has been updated by Akira Tanaka.

File slice_after2.patch added

I updated the patch to simplify argument handling.

----------------------------------------
Feature #9071: Enumerable#slice_after
https://bugs.ruby-lang.org/issues/9071#change-46692

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: Akira Tanaka
* Category:
* Target version:
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 unknown (Guest)
on 2014-05-17 08:34
(Received via mailing list)
Issue #9071 has been updated by Yukihiro Matsumoto.


Accepted.

Matz

----------------------------------------
Feature #9071: Enumerable#slice_after
https://bugs.ruby-lang.org/issues/9071#change-46771

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: Akira Tanaka
* Category:
* Target version:
B11f10c4cd9d53970e7be20caa43f940?d=identicon&s=25 unknown (Guest)
on 2014-05-18 02:06
(Received via mailing list)
Issue #9071 has been updated by Akira Tanaka.

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]

----------------------------------------
Feature #9071: Enumerable#slice_after
https://bugs.ruby-lang.org/issues/9071#change-46783

* Author: Tsuyoshi Sawada
* Status: Closed
* Priority: Normal
* Assignee: Akira Tanaka
* Category:
* Target version:
This topic is locked and can not be replied to.