archive (unofficial mirror)
 help / color / Atom feed
Subject: [ruby-core:99422] [Ruby master Feature#17097] `map_min`, `map_max`
Date: Fri, 31 Jul 2020 18:06:21 +0000 (UTC)
Message-ID: <> (raw)
In-Reply-To: <>

Issue #17097 has been updated by Eregon (Benoit Daloze).

To put in context, consider that the expression might be much longer than `.length`.
Then repeating it is not elegant and is duplicated code.

Feature #17097: `map_min`, `map_max`

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
`min`, `min_by`, `max`, `max_by` return the element that leads to the minimum or the maximum value, but I think it is as, or even more, frequent that we are interested in the minimum or the maximum value itself rather than the element. For example, to get the length of the longest string in an array, we do:

%w[aa b cccc dd].max_by(&:length).length # => 4
%w[aa b cccc dd].map(&:length).max # => 4

I propose to have methods that return the minimum or the maximum value. Temporarily calling them `map_min`, `map_max`, they should work like this:

%w[aa b cccc dd].map_max(&:length) # => 4

`map_min`, `map_max` are implementation-centered names, so perhaps better names should replace them, just like `yield_self` was replaced by `then`.


  parent reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31 12:33 [ruby-core:99418] " sawadatsuyoshi
2020-07-31 12:37 ` [ruby-core:99419] " nobu
2020-07-31 13:51 ` [ruby-core:99420] " grzegorz.jakubiak
2020-07-31 18:03 ` [ruby-core:99421] " eregontp
2020-07-31 18:06 ` eregontp [this message]
2020-08-01  0:56 ` [ruby-core:99425] " marcandre-ruby-core
2020-08-01  3:53 ` [ruby-core:99428] " sawadatsuyoshi

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:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link archive (unofficial mirror)

Archives are clonable: git clone --mirror

Example config snippet for mirrors

Newsgroups are available over NNTP:

 note: .onion URLs require Tor:

AGPL code for this site: git clone