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 12ED21F5AE for ; Fri, 31 Jul 2020 18:03:34 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 92D29120B28; Sat, 1 Aug 2020 03:02:55 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (unknown [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id EBCD2120B1A for ; Sat, 1 Aug 2020 03:02:53 +0900 (JST) Received: by filterdrecv-p3mdw1-7ff865655c-r6gqk with SMTP id filterdrecv-p3mdw1-7ff865655c-r6gqk-19-5F245CDF-DB 2020-07-31 18:03:11.87574169 +0000 UTC m=+172018.362702675 Received: from herokuapp.com (unknown) by geopod-ismtpd-6-1 (SG) with ESMTP id cR3e18JlTSCFsMOp0E5srA for ; Fri, 31 Jul 2020 18:03:11.776 +0000 (UTC) Date: Fri, 31 Jul 2020 18:03:11 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75249 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?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr0eEHiCn=2FNf4pN19sAyC+?= =?us-ascii?Q?yC0w63J55puT7XUOgygofR5Soq5z6bx2Ya9Udam?= =?us-ascii?Q?yQ4IybLeaRo2fLSuo6ylEHHm01j3Hw3bZWk=2FCrF?= =?us-ascii?Q?gocja5BxCbEvUT09kk2GQGLKtK6Fcv+zLOyAbBh?= =?us-ascii?Q?57GT3CIZCdxU1i1s=2FvJJ8Ty1Vjm5Spg023LO2dz?= =?us-ascii?Q?HDBN5Qr2+mD97tpmw=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99421 Subject: [ruby-core:99421] [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). I actually regularly wanted such behavior, but min_by/max_by do not return the result of the block but the element (which makes sense). And `.map {}.min/max` works but is inefficient by generating an intermediate Array. Maybe we should add some keyword argument to min_by/max_by? ---------------------------------------- Feature #17097: `map_min`, `map_max` https://bugs.ruby-lang.org/issues/17097#change-86874 * 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/