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=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 DDF271F86C for ; Sun, 29 Nov 2020 23:41:07 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 2362112099A; Mon, 30 Nov 2020 08:40:19 +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 5AF6512096C for ; Mon, 30 Nov 2020 08:40:16 +0900 (JST) Received: by filterdrecv-p3mdw1-5f8d7bb6d9-xb6ss with SMTP id filterdrecv-p3mdw1-5f8d7bb6d9-xb6ss-21-5FC43189-25 2020-11-29 23:40:57.988771067 +0000 UTC m=+1134599.559321669 Received: from herokuapp.com (unknown) by ismtpd0024p1iad2.sendgrid.net (SG) with ESMTP id P5cc7QznSiOTBS2Wr708Cw for ; Sun, 29 Nov 2020 23:40:57.952 +0000 (UTC) Date: Sun, 29 Nov 2020 23:40:58 +0000 (UTC) From: fluff@lukeswart.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 77020 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 8421 X-Redmine-Issue-Author: Hanmac X-Redmine-Sender: modulitos 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?R10JVld9fzTDoUdawmgbbugWWXNLNenNpqTEWZqTDL0+q5urO2uvh9dijgoLJH?= =?us-ascii?Q?hP7qhLEB6iLbd5cwMfcPPFHASb7LTcDM1=2F65bf9?= =?us-ascii?Q?7oVO3ZRZxy1e8vAiFh=2FhgZMgQ+12KNdkW45axNq?= =?us-ascii?Q?xSwvk8XTGTlPOX0Rm7+L1QRBw8VYHhMXStA+2oU?= =?us-ascii?Q?2lRFOvtoRABixk+N2gC524n+eXvJmVJlnWNQCaR?= =?us-ascii?Q?mh22x8eMxBH5oa9X4=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 101145 Subject: [ruby-core:101145] [Ruby master Feature#8421] add Enumerable#find_map and Enumerable#find_all_map 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 #8421 has been updated by modulitos (Lucas Swart). matz (Yukihiro Matsumoto) wrote in #note-1: > Could you tell me a concrete use-case of your find_map and find_all_map? > Usually a block for find/find_all gives boolean so that I personally have never wanted the return value from it. > > Matz. In Ruby 2.7, I think we can use `enumerable.lazy.filter_map{..}.first` as an equivalent for `.find_map{..}` matz (Yukihiro Matsumoto) wrote in #note-1: > Could you tell me a concrete use-case of your find_map and find_all_map? > Usually a block for find/find_all gives boolean so that I personally have never wanted the return value from it. > > Matz. ---------------------------------------- Feature #8421: add Enumerable#find_map and Enumerable#find_all_map https://bugs.ruby-lang.org/issues/8421#change-88830 * Author: Hanmac (Hans Mackowiak) * Status: Feedback * Priority: Normal ---------------------------------------- currently if you have an Enumerable and you want to return the return value of #find you need eigther: (o = enum.find(block) && block.call(o)) || nil or enum.inject(nil) {|ret,el| ret || block.call(el)} neigher of them may be better than an directly maked method same for #find_all_map enum.lazy.map(&:block).find_all{|el| el} it may work but it is not so good -- https://bugs.ruby-lang.org/