[#91458] [Ruby trunk Feature#4475] default variable name for parameter — matz@...
Issue #4475 has been updated by matz (Yukihiro Matsumoto).
3 messages
2019/02/07
[ruby-core:91381] [Ruby trunk Feature#11076] Enumerable method count_by
From:
duerst@...
Date:
2019-02-02 06:21:33 UTC
List:
ruby-core #91381
Issue #11076 has been updated by duerst (Martin D端rst).
sawa (Tsuyoshi Sawada) wrote:
> Since this feature is an inferior variant of `group_by` in the sense that it reduces the value arrays into their lengths, what about naming the method `group`?
Please not. The `_by` indicates that there is some specific criterion for grouping. This is the same for this method, so removing the `_by` is very strange. Also, the fact that the result contains numbers, not the actual groups, is completely lost.
Compared with this, `count_by` is much better, and so is `tally`. Other possibilities might be `group_by_and_count` or `count_by_group` or something similar.
----------------------------------------
Feature #11076: Enumerable method count_by
https://bugs.ruby-lang.org/issues/11076#change-76636
* Author: haraldb (Harald B旦ttiger)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I very often use `Hash[array.group_by{|x|x}.map{|x,y|[x,y.size]}]`.
Would be nice with to have a method called `count_by`:
~~~ruby
array = ['aa', 'aA', 'bb', 'cc']
p array.count_by(&:downcase) #=> {'aa'=>2,'bb'=>1,'cc'=>1}
~~~
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>