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=-3.9 required=3.0 tests=AWL,BAYES_00, 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 7BC881F5AE for ; Sat, 1 Aug 2020 00:56:41 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 9ED5C120B77; Sat, 1 Aug 2020 09:56:07 +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 A51FE120B73 for ; Sat, 1 Aug 2020 09:56:04 +0900 (JST) Received: by filterdrecv-p3iad2-d8cc6d457-kzc2c with SMTP id filterdrecv-p3iad2-d8cc6d457-kzc2c-19-5F24BDC0-1E 2020-08-01 00:56:32.2394453 +0000 UTC m=+197294.086954543 Received: from herokuapp.com (unknown) by ismtpd0015p1iad2.sendgrid.net (SG) with ESMTP id R1AbjN9eTM65HIwRNTadsA for ; Sat, 01 Aug 2020 00:56:32.120 +0000 (UTC) Date: Sat, 01 Aug 2020 00:56:32 +0000 (UTC) From: marcandre-ruby-core@marc-andre.ca Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75253 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17097 X-Redmine-Issue-Author: sawa X-Redmine-Sender: marcandre 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?6=2FIMxCQLDposcQf5wmbDAtfaKduBAO0bKyhL3BGZtMQ5q7K2TvpbN6A7JIyt9E?= =?us-ascii?Q?aOhW=2F7sOhZeDW5B3vPow3GxE2gszB1KccwVwYKU?= =?us-ascii?Q?Fb97eEuYyxC8kYidJBzem5OehI9CiLP218v5yvB?= =?us-ascii?Q?jr49er2Jmrs+SlWcZQJl+y6nbbHjuY5yv=2FK297T?= =?us-ascii?Q?XPwvRNZ03ZXnjjNMG6FFuSGg6624fb6gPp3ICba?= =?us-ascii?Q?X05sxZBKBoZwOFSXa4gmFI6ot840gx68tKCFyP?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99425 Subject: [ruby-core:99425] [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 marcandre (Marc-Andre Lafortune). @nobu is right, we're not going to add `map_` for everything. Eregon (Benoit Daloze) wrote in #note-6: > Then repeating it is not elegant and is duplicated code. I don't see why there would be repetition. Just do `enum.map { very_long_expression }.max`... Please benchmark the time it takes to generate the intermediate array. My guess is that it's typically negligible. ---------------------------------------- Feature #17097: `map_min`, `map_max` https://bugs.ruby-lang.org/issues/17097#change-86878 * 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/