From: joshua.goodall@... Date: 2019-10-11T02:34:01+00:00 Subject: [ruby-core:95300] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map Issue #15323 has been updated by inopinatus (Joshua GOODALL). Could this take argument as well? I'd be keen for something in the spirit of `Enumerable#grep` but where an (optional) pattern evaluates the result of the block, rather than each element of the array. If omitted, there's the default test. I'd love to be able to write `bottles.filter_map(18.., &:age)` or `dependencies.filter_map(/GPL/) { |lib| lib.license.name.upcase }`. ---------------------------------------- Feature #15323: [PATCH] Proposal: Add Enumerable#filter_map https://bugs.ruby-lang.org/issues/15323#change-81984 * 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: