Project

General

Profile

Actions

Feature #17097

open

`map_min`, `map_max`

Added by sawa (Tsuyoshi Sawada) over 4 years ago. Updated almost 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:99418]

Description

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like1Like1Like0Like0