From: jonathan@... Date: 2019-10-06T20:43:44+00:00 Subject: [ruby-core:95251] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map 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 filters differently than `Enumerable#filter` (which removes both false and nil 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�nez) * Status: Closed * Priority: Normal * Assignee: * Target version: ---------------------------------------- This is a proposal for a combined `filter` + `map` method (https://bugs.ruby-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? } #=> [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: