[ruby-core:91244] [Ruby trunk Feature#11076] Enumerable method count_by

From: joshua.goodall@...
Date: 2019-01-24 04:22:08 UTC
List: ruby-core #91244
Issue #11076 has been updated by inopinatus (Joshua GOODALL).


A histogram refers to counts of items in ranges of otherwise continuous data. But this function is more general than that, so I think `histogram` is too specific a term.

For this native English speaker, `tally` is the most precisely fitted method name.


----------------------------------------
Feature #11076: Enumerable method count_by
https://bugs.ruby-lang.org/issues/11076#change-76489

* 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>

In This Thread

Prev Next