ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:66113] [ruby-trunk - Feature #10482] [Open] Allow ignored items to vary in `Enumerable#chunk`.
       [not found] <redmine.issue-10482.20141106075637@ruby-lang.org>
@ 2014-11-06  7:56 ` sawadatsuyoshi
  2014-11-06  8:01 ` [ruby-core:66114] [ruby-trunk - Feature #10482] " sawadatsuyoshi
  2014-11-11 10:08 ` [ruby-core:66202] [ruby-trunk - Feature #10482] [Feedback] " akr
  2 siblings, 0 replies; 3+ messages in thread
From: sawadatsuyoshi @ 2014-11-06  7:56 UTC (permalink / raw
  To: ruby-core

Issue #10482 has been reported by Tsuyoshi Sawada.

----------------------------------------
Feature #10482: Allow ignored items to vary in `Enumerable#chunk`.
https://bugs.ruby-lang.org/issues/10482

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
In #5663, regarding a method proposed, Yehuda Katz's writes:

~~~
The only caveat is that it would be impossible to intentionally return nil here; suggestions welcome.
~~~

I would like to note here that the same problem exists with `Enumerable#chunk`. Currently, when the key value is `nil`, the corresponding items are thrown out. That may be useful sometimes, but sometimes, silently doing so causes a hard-to-detect bug. At least, there should be a way to change what is ignored (which would not break existing code using it), and ideally, nothing should be thrown out unless explicitly specified (which would break existing code).

I propose `Enumerable#chunk` to take an optional named parameter `ignore`, which switches what is ignored. When something other than `nil` is specified, then `nil` should not be ignored:

~~~ruby
[:foo1, :foo2, "bar", nil, nil].chunk(ignore: String){|e| e.class}
# => [[Symbol, [:foo1, :foo2]], [NilClass, [nil, nil]]]
~~~

When you don't want anything to be ignored, then the parameter should be set to something that does not appear in the receiver:

~~~ruby
[:foo1, :foo2, "bar", nil, nil].chunk(ignore: "nothing to ignore"){|e| e.class}
# => [[Symbol, [:foo1, :foo2]], [String, ["bar"]], [NilClass, [nil, nil]]]
~~~




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:66114] [ruby-trunk - Feature #10482] Allow ignored items to vary in `Enumerable#chunk`.
       [not found] <redmine.issue-10482.20141106075637@ruby-lang.org>
  2014-11-06  7:56 ` [ruby-core:66113] [ruby-trunk - Feature #10482] [Open] Allow ignored items to vary in `Enumerable#chunk` sawadatsuyoshi
@ 2014-11-06  8:01 ` sawadatsuyoshi
  2014-11-11 10:08 ` [ruby-core:66202] [ruby-trunk - Feature #10482] [Feedback] " akr
  2 siblings, 0 replies; 3+ messages in thread
From: sawadatsuyoshi @ 2014-11-06  8:01 UTC (permalink / raw
  To: ruby-core

Issue #10482 has been updated by Tsuyoshi Sawada.


Sorry, the example was wrong; I mistook `nil` and `NilClass`. But I hope you get the point.

----------------------------------------
Feature #10482: Allow ignored items to vary in `Enumerable#chunk`.
https://bugs.ruby-lang.org/issues/10482#change-49824

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
In #5663, regarding a method proposed, Yehuda Katz's writes:

~~~
The only caveat is that it would be impossible to intentionally return nil here; suggestions welcome.
~~~

I would like to note here that the same problem exists with `Enumerable#chunk`. Currently, when the key value is `nil`, the corresponding items are thrown out. That may be useful sometimes, but sometimes, silently doing so causes a hard-to-detect bug. At least, there should be a way to change what is ignored (which would not break existing code using it), and ideally, nothing should be thrown out unless explicitly specified (which would break existing code).

I propose `Enumerable#chunk` to take an optional named parameter `ignore`, which switches what is ignored. When something other than `nil` is specified, then `nil` should not be ignored:

~~~ruby
[:foo1, :foo2, "bar", nil, nil].chunk(ignore: String){|e| e.class}
# => [[Symbol, [:foo1, :foo2]], [NilClass, [nil, nil]]]
~~~

When you don't want anything to be ignored, then the parameter should be set to something that does not appear in the receiver:

~~~ruby
[:foo1, :foo2, "bar", nil, nil].chunk(ignore: "nothing to ignore"){|e| e.class}
# => [[Symbol, [:foo1, :foo2]], [String, ["bar"]], [NilClass, [nil, nil]]]
~~~




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:66202] [ruby-trunk - Feature #10482] [Feedback] Allow ignored items to vary in `Enumerable#chunk`.
       [not found] <redmine.issue-10482.20141106075637@ruby-lang.org>
  2014-11-06  7:56 ` [ruby-core:66113] [ruby-trunk - Feature #10482] [Open] Allow ignored items to vary in `Enumerable#chunk` sawadatsuyoshi
  2014-11-06  8:01 ` [ruby-core:66114] [ruby-trunk - Feature #10482] " sawadatsuyoshi
@ 2014-11-11 10:08 ` akr
  2 siblings, 0 replies; 3+ messages in thread
From: akr @ 2014-11-11 10:08 UTC (permalink / raw
  To: ruby-core

Issue #10482 has been updated by Akira Tanaka.

Status changed from Open to Feedback

The method has a form which is incompatible with your proposal: enum.chunk(initial_state) { |elt, state| ... } 

However I deprecated the form (since Ruby 2.2), your porposal may be considerable in future.

----------------------------------------
Feature #10482: Allow ignored items to vary in `Enumerable#chunk`.
https://bugs.ruby-lang.org/issues/10482#change-49899

* Author: Tsuyoshi Sawada
* Status: Feedback
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
In #5663, regarding a method proposed, Yehuda Katz's writes:

~~~
The only caveat is that it would be impossible to intentionally return nil here; suggestions welcome.
~~~

I would like to note here that the same problem exists with `Enumerable#chunk`. Currently, when the key value is `nil`, the corresponding items are thrown out. That may be useful sometimes, but sometimes, silently doing so causes a hard-to-detect bug. At least, there should be a way to change what is ignored (which would not break existing code using it), and ideally, nothing should be thrown out unless explicitly specified (which would break existing code).

I propose `Enumerable#chunk` to take an optional named parameter `ignore`, which switches what is ignored. When something other than `nil` is specified, then `nil` should not be ignored:

~~~ruby
[:foo1, :foo2, "bar", nil, nil].chunk(ignore: String){|e| e.class}
# => [[Symbol, [:foo1, :foo2]], [NilClass, [nil, nil]]]
~~~

When you don't want anything to be ignored, then the parameter should be set to something that does not appear in the receiver:

~~~ruby
[:foo1, :foo2, "bar", nil, nil].chunk(ignore: "nothing to ignore"){|e| e.class}
# => [[Symbol, [:foo1, :foo2]], [String, ["bar"]], [NilClass, [nil, nil]]]
~~~




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-11 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-10482.20141106075637@ruby-lang.org>
2014-11-06  7:56 ` [ruby-core:66113] [ruby-trunk - Feature #10482] [Open] Allow ignored items to vary in `Enumerable#chunk` sawadatsuyoshi
2014-11-06  8:01 ` [ruby-core:66114] [ruby-trunk - Feature #10482] " sawadatsuyoshi
2014-11-11 10:08 ` [ruby-core:66202] [ruby-trunk - Feature #10482] [Feedback] " akr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).