From: ruby-core@... Date: 2016-09-21T14:53:11+00:00 Subject: [ruby-core:77336] [Ruby trunk Feature#2172] Enumerable#chunk with no block Issue #2172 has been updated by Marc-Andre Lafortune. Assignee changed from Akira Tanaka to Yukihiro Matsumoto Matz, would you agree to return enumerator for `chunk` with a block? This is useful in particular to chain it with `with_index` A real case example is to summarize a list of integers into ranges. Currently, we need: integers.enum_for(:chunk).with_index { |x, idx| x - idx }.map do |diff, group| [group.first, group.last] end Ref: http://stackoverflow.com/questions/8621733/how-do-i-summarize-array-of-integers-as-an-array-of-ranges ---------------------------------------- Feature #2172: Enumerable#chunk with no block https://bugs.ruby-lang.org/issues/2172#change-60582 * Author: Marc-Andre Lafortune * Status: Assigned * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- =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 -- https://bugs.ruby-lang.org/ Unsubscribe: