From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 00A851F5AE for ; Sat, 1 Aug 2020 03:53:27 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 78859120B84; Sat, 1 Aug 2020 12:52:54 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 8C919120B83 for ; Sat, 1 Aug 2020 12:52:51 +0900 (JST) Received: by filterdrecv-p3mdw1-7ff865655c-m2ckz with SMTP id filterdrecv-p3mdw1-7ff865655c-m2ckz-20-5F24E72F-1E 2020-08-01 03:53:19.36612211 +0000 UTC m=+207428.355309938 Received: from herokuapp.com (unknown) by ismtpd0041p1mdw1.sendgrid.net (SG) with ESMTP id KwyHDpN6Ra-u71i5AJ8MZA for ; Sat, 01 Aug 2020 03:53:19.316 +0000 (UTC) Date: Sat, 01 Aug 2020 03:53:19 +0000 (UTC) From: sawadatsuyoshi@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75256 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17097 X-Redmine-Issue-Author: sawa X-Redmine-Sender: sawa X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?jFXA8Rt481sXUUIO9tYW1AJlMOZdNdlSw=2F5TfLCefGs5A7cFonfb+YrrmZxd8b?= =?us-ascii?Q?zrqJf0Qww650V4tAF=2FBYI1tvnMnQ9nnfaRmglXZ?= =?us-ascii?Q?7aTkA5ZVTMtm6CwmxR46wrMWSfLq+aQ2=2FEAdfx5?= =?us-ascii?Q?4nGEl9kYeBxvhNIakfxSoKTOS3kOACcFcsqZsDt?= =?us-ascii?Q?V=2FM1vJJ+PFAuJWR+tuoAx1zPknraHOEEd8xbcuC?= =?us-ascii?Q?AJ023UOurUaeAv4ls=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99428 Subject: [ruby-core:99428] [Ruby master Feature#17097] `map_min`, `map_max` X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17097 has been updated by sawa (Tsuyoshi Sawada). I do not understand why the proposal has to be extended to all other `Enumerable` methods. My point is semantic. I do not see many use cases where I am interested in the element that is related to the min/max value but am not interested in the min/max value. ---------------------------------------- Feature #17097: `map_min`, `map_max` https://bugs.ruby-lang.org/issues/17097#change-86880 * 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/