From: jonathan@hefner.pro
To: ruby-core@ruby-lang.org
Subject: [ruby-core:92526] [Ruby trunk Feature#11076] Enumerable method count_by
Date: Thu, 02 May 2019 14:41:13 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-77888.20190502144113.189eff47deed1664@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11076.20150419203854@ruby-lang.org
Issue #11076 has been updated by jonathanhefner (Jonathan Hefner).
> "map + select" is much more frequent, but it is not introduced yet
I think it would also be nice if `filter_map` was added. However, a specific justification for adding `tally_by` is to avoid an extra array allocation. `filter_map` can already be expressed as `map { ... }.compact!` to avoid allocating an extra array. But there is no way to avoid an extra allocation with `map { ... }.tally`.
----------------------------------------
Feature #11076: Enumerable method count_by
https://bugs.ruby-lang.org/issues/11076#change-77888
* Author: haraldb (Harald Böttiger)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* 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>
prev parent reply other threads:[~2019-05-02 14:46 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-11076.20150419203854@ruby-lang.org>
2015-04-19 20:38 ` [ruby-core:68932] [Ruby trunk - Feature #11076] [Open] Enumerable method count_by bottiger
2015-04-20 1:32 ` [ruby-core:68933] [Ruby trunk - Feature #11076] " shevegen
2015-04-20 6:50 ` [ruby-core:68934] " nobu
2015-04-20 8:14 ` [ruby-core:68935] " duerst
2015-04-20 14:08 ` [ruby-core:68938] " ko1
2015-04-20 15:35 ` [ruby-core:68941] " bottiger
2018-06-29 1:01 ` [ruby-core:87673] [Ruby trunk Feature#11076] " keystonelemur
2018-08-09 7:58 ` [ruby-core:88373] " knu
2018-08-09 18:15 ` [ruby-core:88403] " keystonelemur
2018-08-10 11:37 ` [ruby-core:88436] " janfri26
2018-08-21 17:55 ` [ruby-core:88598] " dgjones
2018-12-13 0:23 ` [ruby-core:90462] " keystonelemur
2018-12-13 10:32 ` [ruby-core:90502] " janfri26
2018-12-14 17:35 ` [ruby-core:90529] " oliverp
2019-01-24 4:22 ` [ruby-core:91244] " joshua.goodall
2019-01-24 14:21 ` [ruby-core:91252] " mame
2019-01-25 0:11 ` [ruby-core:91254] " muraken
2019-01-29 1:05 ` [ruby-core:91312] " keystonelemur
2019-01-29 2:52 ` [ruby-core:91314] " nobu
2019-01-29 10:42 ` [ruby-core:91317] " eregontp
2019-02-02 3:01 ` [ruby-core:91380] " sawadatsuyoshi
2019-02-02 6:21 ` [ruby-core:91381] " duerst
2019-02-06 13:04 ` [ruby-core:91429] " mame
2019-02-07 7:47 ` [ruby-core:91460] " matz
2019-02-07 7:51 ` [ruby-core:91462] " mame
2019-02-07 8:10 ` [ruby-core:91465] " mame
2019-02-14 19:36 ` [ruby-core:91548] " keystonelemur
2019-02-15 0:30 ` [ruby-core:91549] " mame
2019-05-02 14:41 ` jonathan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-77888.20190502144113.189eff47deed1664@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).