[ruby-core:95248] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
From:
jonathan@...
Date:
2019-10-06 19:16:46 UTC
List:
ruby-core #95248
Issue #15323 has been updated by jonathanhefner (Jonathan Hefner).
nobu (Nobuyoshi Nakada) wrote:
> IIRC, at the last meeting (20190522), the conclusion was that this method should select non-nil values only, like as `Array#compact`.
> Am I correct?
Checking master, it looks like this was not addressed. I agree it would be more intuitive for `filter_map` to behave like `map{ ... }.compact`. Rejecting `false` values seems like a "gotcha" / footgun.
I have submitted a PR: https://github.com/ruby/ruby/pull/2530
----------------------------------------
Feature #15323: [PATCH] Proposal: Add Enumerable#filter_map
https://bugs.ruby-lang.org/issues/15323#change-81925
* Author: alfonsojimenez (Alfonso Jim駭ez)
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>