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

From: ko1@...
Date: 2015-04-20 14:08:21 UTC
List: ruby-core #68938
Issue #11076 has been updated by Koichi Sasada.


+1

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

* Author: Harald B=C3=B6ttiger
* Status: Open
* Priority: Low
* Assignee:=20
----------------------------------------
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 =3D ['aa', 'aA', 'bb', 'cc']
p array.count_by(&:downcase) #=3D> {'aa'=3D>2,'bb'=3D>1,'cc'=3D>1}
~~~



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

In This Thread

Prev Next