Project

General

Profile

Feature #2172

Enumerable#chunk with no block

Added by Marc-Andre Lafortune almost 7 years ago. Updated over 3 years ago.

Status:
Assigned
Priority:
Normal
Assignee:
[ruby-core:25912]

Description

=begin
What should "(1..3).chunk" (i.e. without a block) do?

It issued an
ArgumentError: tried to create Proc object without a block

I changed the error message to "no block given" which I hope to be more informative, but maybe there is something more useful to do here?

A default block of {|x| x} doesn't seem all that useful.

Returning an enumerator that, upon completion, will return an enumerator would probably be better, but could also be a bit confusing if someone doesn't realize he forgot to specify the block?

Thanks to Run Paint for raising the question when writing the rubyspec for #chunk.
=end

History

#1 Updated by Yui NARUSE almost 7 years ago

  • Status changed from Open to Assigned
  • Assignee changed from Yukihiro Matsumoto to Akira Tanaka

=begin

=end

#2 Updated by Marc-Andre Lafortune over 6 years ago

  • Category set to core
  • Assignee changed from Akira Tanaka to Yukihiro Matsumoto
  • Target version set to 1.9.2

=begin

=end

#3 Updated by Marc-Andre Lafortune over 6 years ago

  • Assignee changed from Yukihiro Matsumoto to Akira Tanaka

=begin

=end

#4 Updated by Marc-Andre Lafortune over 6 years ago

=begin
Maybe a default block of {|x| x} can be useful for some people...

http://stackoverflow.com/questions/2516312/remove-adjacent-identical-elements-in-a-ruby-array
=end

#5 Updated by Kazuhiro NISHIYAMA over 6 years ago

  • Target version changed from 1.9.2 to 2.0.0

=begin

=end

#6 [ruby-core:47020] Updated by Arnau Sanchez almost 4 years ago

Any decision about this? For me it's a clear +1, chunking by the values unchanged is very common (not that it's representative, but I checked my code: 4 ocurrences of chunk, all with the identity block)

#7 [ruby-core:48520] Updated by Akira Tanaka over 3 years ago

  • Description updated (diff)
  • Target version changed from 2.0.0 to next minor

Also available in: Atom PDF