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-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00, FROM_SUSPICIOUS_NTLD,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 648181F4BD for ; Sun, 6 Oct 2019 20:43:54 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 918FC1209AD; Mon, 7 Oct 2019 05:43:43 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id D81471209A6 for ; Mon, 7 Oct 2019 05:43:41 +0900 (JST) Received: by filter0138p3mdw1.sendgrid.net with SMTP id filter0138p3mdw1-16790-5D9A5200-1E 2019-10-06 20:43:44.343051431 +0000 UTC m=+267389.945468948 Received: from herokuapp.com (unknown [34.201.109.215]) by ismtpd0027p1mdw1.sendgrid.net (SG) with ESMTP id ucBjJQDoSVWUwsXHVPiU6Q for ; Sun, 06 Oct 2019 20:43:44.304 +0000 (UTC) Date: Sun, 06 Oct 2019 20:43:44 +0000 (UTC) From: jonathan@hefner.pro Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70838 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15323 X-Redmine-Issue-Author: alfonsojimenez X-Redmine-Sender: jonathanhefner 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?y87fQmSTkDB0MB8oF=2FSr+wCExKhWErwiIVXChRtBifvryLEbeTRFPcZmZZMkGG?= =?us-ascii?Q?GNvXwIPFkvK90Ed8NdgacOoDRoi0fcxoALF69kf?= =?us-ascii?Q?Q+j4gc7u48hqw9qatDP6LEodNSagvP0C0qqecbz?= =?us-ascii?Q?F1KY8UAJN7FmU1nL=2FJRiPraCGXacy398jfT=2FGiy?= =?us-ascii?Q?Eb7jA8uVBT7MXL5sYZbKyedT4vMVQQv9K0A=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95251 Subject: [ruby-core:95251] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15323 has been updated by jonathanhefner (Jonathan Hefner). Eregon (Benoit Daloze) wrote: > but to me it sounds surprising that a method with `filter` in its name fi= lters differently than `Enumerable#filter` (which removes both false and ni= l values). Yes, I suppose that is surprising too... But, I think that throwing away `= false` values is still a footgun. If I write: ```ruby records.filter_map{|record| record.send(field) if record.valid? } ``` I would expect to get a value for every valid record, no matter what `field= ` is. Should the name of `filter_map` be reconsidered? ---------------------------------------- Feature #15323: [PATCH] Proposal: Add Enumerable#filter_map https://bugs.ruby-lang.org/issues/15323#change-81928 * Author: alfonsojimenez (Alfonso Jim=E9nez) * Status: Closed * Priority: Normal * Assignee: = * Target version: = ---------------------------------------- This is a proposal for a combined `filter` + `map` method (https://bugs.rub= y-lang.org/issues/5663). This method both filters and maps the elements of an enumerable in just one= iteration: ~~~ ruby (1..10).filter_map { |i| i * 2 if i.even? } #=3D> [4, 8, 12, 16, 20] ~~~ GitHub PR: https://github.com/ruby/ruby/pull/2017 = ---Files-------------------------------- 0001-Adding-Enumerable-filter_map.patch (4.61 KB) -- = https://bugs.ruby-lang.org/ Unsubscribe: