From: "baweaver (Brandon Weaver) via ruby-core" Date: 2022-12-23T04:30:59+00:00 Subject: [ruby-core:111390] [Ruby master Feature#17097] `map_min`, `map_max` Issue #17097 has been updated by baweaver (Brandon Weaver). For the sake of naming conventions I would personally lean towards `map_max` to match methods like `filter_map`, and while this does not necessarily extend to _all_ Enumerable methods I would wonder if there's another conversation later to be had about composite Enumerable methods. On this particular ticket though I believe that the use-case is common enough, and in many cases may be what the developer intends. ---------------------------------------- Feature #17097: `map_min`, `map_max` https://bugs.ruby-lang.org/issues/17097#change-100765 * 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: ```ruby %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: ```ruby %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`. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/