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

From: nobu@...
Date: 2015-04-20 06:50:51 UTC
List: ruby-core #68934
Issue #11076 has been updated by Nobuyoshi Nakada.

Description updated

https://github.com/ruby/ruby/compare/trunk...nobu:feature/11076-Enumerable%=
23count_by

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

* 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