[ruby-core:95679] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map

From: shevegen@...
Date: 2019-11-04 21:32:40 UTC
List: ruby-core #95679
Issue #15323 has been updated by shevegen (Robert A. Heiler).


Jonathan recently added this to the upcoming developer discussion (at https://bugs.ruby-lang.org/issues/16262),
in regards as to whether the current behaviour is correct, or whether it should include non-nil values as well.

The question is whether the behaviour should be like Array#compact or not.

I can not say much about Array#compact, but from the name filter_map alone, I would assume that first a filter
is used (as a "positive" .select), and then the .map is applied. If this reasoning makes any sense to anyone
else, then I believe that the behaviour shown by .filter_map as-is is correct and should be retained. But
this is just my opinion - my reasoning comes primarily from the name itself (.filter_map that is).

----------------------------------------
Feature #15323: [PATCH] Proposal: Add Enumerable#filter_map
https://bugs.ruby-lang.org/issues/15323#change-82466

* 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>

In This Thread

Prev Next