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 554991F5AE for ; Fri, 31 Jul 2020 18:06:26 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 5542C120B6C; Sat, 1 Aug 2020 03:05:55 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (unknown [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 746D3120B6A for ; Sat, 1 Aug 2020 03:05:53 +0900 (JST) Received: by filterdrecv-p3iad2-d8cc6d457-6kjsg with SMTP id filterdrecv-p3iad2-d8cc6d457-6kjsg-18-5F245D9D-71 2020-07-31 18:06:21.327928695 +0000 UTC m=+172678.139686921 Received: from herokuapp.com (unknown) by ismtpd0009p1iad2.sendgrid.net (SG) with ESMTP id pgprjEECQRWe-H6cvHQtbQ for ; Fri, 31 Jul 2020 18:06:21.318 +0000 (UTC) Date: Fri, 31 Jul 2020 18:06:21 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75250 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17097 X-Redmine-Issue-Author: sawa X-Redmine-Sender: Eregon 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?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr3cG6nBCTACmsvniFrSIe?= =?us-ascii?Q?p+UFVcOyltkweZtWMvsZLJgdnW4966lchOfKRbd?= =?us-ascii?Q?B2WjuscngqJc9Ei+xJxeKEnCfCPQhc5K6j54pBr?= =?us-ascii?Q?WI4Sg8=2FrUf8Nevypjjw9Tu7HfbdSSrCX7LzGq+H?= =?us-ascii?Q?soHQehKdVEi50dO0gfBAQUng399=2FVGw0pID9yhI?= =?us-ascii?Q?68HT4yWxot092=2Fi2M=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99422 Subject: [ruby-core:99422] [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 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` https://bugs.ruby-lang.org/issues/17097#change-86875 * 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/