ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:89907] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
@ 2018-11-20 11:59 ` me
  2018-11-20 14:29 ` [ruby-core:89908] " tonysunnymails
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: me @ 2018-11-20 11:59 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been reported by alfonsojimenez (Alfonso Jiménez).

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

* Author: alfonsojimenez (Alfonso Jiménez)
* Status: Open
* 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]
~~~



 

---Files--------------------------------
0001-Adding-Enumerable-filter_map.patch (4.55 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:89908] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
  2018-11-20 11:59 ` [ruby-core:89907] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map me
@ 2018-11-20 14:29 ` tonysunnymails
  2018-11-20 17:07 ` [ruby-core:89912] " shevegen
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: tonysunnymails @ 2018-11-20 14:29 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by tny (Tony Sunny).


Could't we use reduce for this?
~~~ ruby
(1..10).reduce([]) { |a, i| i.even? ? a << i : a }
~~~


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

* Author: alfonsojimenez (Alfonso Jiménez)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:89912] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
  2018-11-20 11:59 ` [ruby-core:89907] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map me
  2018-11-20 14:29 ` [ruby-core:89908] " tonysunnymails
@ 2018-11-20 17:07 ` shevegen
  2018-12-14 19:58 ` [ruby-core:90531] " nardonykolyszyn
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: shevegen @ 2018-11-20 17:07 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by shevegen (Robert A. Heiler).


I think the functionality, that is to combine .filter (be it select
or reject, is secondary to me), and .map, could be useful. I don't
really need it myself but I find it is not entirely out of the question
that others may find it useful.

There is, IMO, only one real drawback, if we ignore the functionality
aspect (where you'd have to ask matz anyway), and this is that I
think the two-word methods can be quite clumsy.

Not just .filter_map but also .yield_self, which eventually had an
alias called .then. If we ignore the question as to whether .then
is a good name (or .yield_self), one advantage that .then has
is that it is shorter.

Succinct expression is not always necessarily the best; but in this
case, I think single-word methods are very often better than two-word
methods.

.reduce() has, in my opinion, a slight other disadvantage, and that
is that people have to explicitely pass an [] (as in the example
here), which is not always easy to remember. (For me it is hard
to remember because I rarely use .reduce either).

This is just my opinion, though. I do not really have any strong pro
or con way about the feature itself; only a very tiny dislike of
.filter_map as name. But it is not really a strong contra opinion
either way. (My biggest look ahead is on ruby's jit/mjit ... :D)

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

* Author: alfonsojimenez (Alfonso Jiménez)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:90531] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-11-20 17:07 ` [ruby-core:89912] " shevegen
@ 2018-12-14 19:58 ` nardonykolyszyn
  2018-12-14 20:22   ` [ruby-core:90532] " oleynikov
  2018-12-17  3:43 ` [ruby-core:90582] " matthew
                   ` (13 subsequent siblings)
  17 siblings, 1 reply; 19+ messages in thread
From: nardonykolyszyn @ 2018-12-14 19:58 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by devpolish (Nardo Nykolyszyn).


(1..10).map { |e| e.even? ? (e * 2) : e }

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

* Author: alfonsojimenez (Alfonso Jiménez)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:90532] Re: [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
  2018-12-14 19:58 ` [ruby-core:90531] " nardonykolyszyn
@ 2018-12-14 20:22   ` oleynikov
  0 siblings, 0 replies; 19+ messages in thread
From: oleynikov @ 2018-12-14 20:22 UTC (permalink / raw)
  To: Ruby developers; +Cc: ruby-core

nardonykolyszyn@gmail.com wrote:
> (1..10).map { |e| e.even? ? (e * 2) : e }

Yeah, but without `#filter` this is still an array with 10 elements.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:90582] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2018-12-14 19:58 ` [ruby-core:90531] " nardonykolyszyn
@ 2018-12-17  3:43 ` matthew
  2019-02-13  2:41 ` [ruby-core:91524] " shugo
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: matthew @ 2018-12-17  3:43 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by phluid61 (Matthew Kerwin).


tny (Tony Sunny) wrote:
> Could't we use reduce for this?
> ~~~ ruby
> (1..10).reduce([]) { |a, i| i.even? ? a << (i * 2) : a }
> ~~~

Yep, that's mentioned in the original ticket too. There's also #each_with_object that lets you write the block almost the same as in the proposal:

~~~ruby
(1..10).each_with_object([]) { |i, a| a << i * 2 if i.even? }
~~~

The big difference here is you can capture nil/false values, because the filter test is explicitly separated from the map operation.

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

* Author: alfonsojimenez (Alfonso Jiménez)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:91524] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2018-12-17  3:43 ` [ruby-core:90582] " matthew
@ 2019-02-13  2:41 ` shugo
  2019-04-25  9:54 ` [ruby-core:92406] " me
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: shugo @ 2019-02-13  2:41 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by shugo (Shugo Maeda).


+1 for filter_map.

Matz agreed the feature itself before: https://bugs.ruby-lang.org/issues/5663#note-42
The name filter_map is good because other languages have similar names (e.g., filter-map in Scheme).

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

* Author: alfonsojimenez (Alfonso Jiménez)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:92406] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2019-02-13  2:41 ` [ruby-core:91524] " shugo
@ 2019-04-25  9:54 ` me
  2019-04-30 21:35 ` [ruby-core:92505] " grzegorz.jakubiak
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: me @ 2019-04-25  9:54 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by alfonsojimenez (Alfonso Jiménez).


I've updated the patch file increasing the ruby version in *spec/ruby/core/enumerable/filter_map_spec.rb*

`Enumerable#filter_map` was already accepted in the last developers meeting: https://docs.google.com/document/u/2/d/e/2PACX-1vTUCmj7aUdnMAdunG0AZo0AdWK-9jvfXcB7DWYmzGtmPc0IuIPGn7eLARoR5tBd6XUUB08W-hH74k-T/pub

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

* Author: alfonsojimenez (Alfonso Jiménez)
* Status: Open
* 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>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:92505] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2019-04-25  9:54 ` [ruby-core:92406] " me
@ 2019-04-30 21:35 ` grzegorz.jakubiak
  2019-05-22  6:06 ` [ruby-core:92764] " matz
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: grzegorz.jakubiak @ 2019-04-30 21:35 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by greggzst (Grzegorz Jakubiak).


alfonsojimenez (Alfonso Jiménez) wrote:
> I've updated the patch file increasing the ruby version in *spec/ruby/core/enumerable/filter_map_spec.rb*
> 
> `Enumerable#filter_map` was already accepted in the last developers meeting: https://docs.google.com/document/u/2/d/e/2PACX-1vTUCmj7aUdnMAdunG0AZo0AdWK-9jvfXcB7DWYmzGtmPc0IuIPGn7eLARoR5tBd6XUUB08W-hH74k-T/pub

Does the syntax allow for this kind of code?

~~~ruby
(1..10).filter_map(&:even?) { |i| i * 2 }
~~~


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

* Author: alfonsojimenez (Alfonso Jiménez)
* Status: Open
* 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>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:92764] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2019-04-30 21:35 ` [ruby-core:92505] " grzegorz.jakubiak
@ 2019-05-22  6:06 ` matz
  2019-05-23 15:46 ` [ruby-core:92802] " nobu
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: matz @ 2019-05-22  6:06 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by matz (Yukihiro Matsumoto).


I accepted the proposal at the last developer meeting but forgot to post here.
I do reject having both block and block argument at the same time. [ruby-core:92505]
Regarding `filter_map!`, submit a new proposal, if you really needed (with the use-case).

Matz.

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

* Author: alfonsojimenez (Alfonso Jiménez)
* Status: Open
* 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>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:92802] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2019-05-22  6:06 ` [ruby-core:92764] " matz
@ 2019-05-23 15:46 ` nobu
  2019-10-06 19:16 ` [ruby-core:95248] [Ruby master " jonathan
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: nobu @ 2019-05-23 15:46 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by nobu (Nobuyoshi Nakada).


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?


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

* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:95248] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2019-05-23 15:46 ` [ruby-core:92802] " nobu
@ 2019-10-06 19:16 ` jonathan
  2019-10-06 19:22 ` [ruby-core:95249] " eregontp
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jonathan @ 2019-10-06 19:16 UTC (permalink / raw)
  To: ruby-core

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é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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:95249] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2019-10-06 19:16 ` [ruby-core:95248] [Ruby master " jonathan
@ 2019-10-06 19:22 ` eregontp
  2019-10-06 20:43 ` [ruby-core:95251] " jonathan
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: eregontp @ 2019-10-06 19:22 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by Eregon (Benoit Daloze).


Isn't `enum.filter_map { |e| ... }` supposed to be (according to the name) the same as `enum.map { |e| ... }.filter { |e| e }`?

I'm not completely sure what is better, 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).

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

* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:95251] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2019-10-06 19:22 ` [ruby-core:95249] " eregontp
@ 2019-10-06 20:43 ` jonathan
  2019-10-08 21:35 ` [ruby-core:95283] " eregontp
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jonathan @ 2019-10-06 20:43 UTC (permalink / raw)
  To: 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 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:95283] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2019-10-06 20:43 ` [ruby-core:95251] " jonathan
@ 2019-10-08 21:35 ` eregontp
  2019-10-11  2:34 ` [ruby-core:95300] " joshua.goodall
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: eregontp @ 2019-10-08 21:35 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by Eregon (Benoit Daloze).


jonathanhefner (Jonathan Hefner) wrote:
> Eregon (Benoit Daloze) wrote:
> I would expect to get a value for every valid record, no matter what `field` is.

What if `record.send(field)` returns `nil`?
Then the only way is:
```ruby
records.filter { |record| record.valid? }.map { |record| record.send(field) }
```

So this kind of issue is intrinsically there for `filter_map`.
`filter_map` is a footgun if `nil` can be returned.

I see the point that `nil` is like "missing element, filter it out" versus `false` being a regular value (and `true` too).

I tend to agree with you now, I think just filtering out `nil` values would be better than also removing `false`.

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

* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:95300] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2019-10-08 21:35 ` [ruby-core:95283] " eregontp
@ 2019-10-11  2:34 ` joshua.goodall
  2019-11-04 21:32 ` [ruby-core:95679] " shevegen
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: joshua.goodall @ 2019-10-11  2:34 UTC (permalink / raw)
  To: ruby-core

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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:95679] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2019-10-11  2:34 ` [ruby-core:95300] " joshua.goodall
@ 2019-11-04 21:32 ` shevegen
  2019-11-04 21:35 ` [ruby-core:95681] " shevegen
  2019-11-28  4:19 ` [ruby-core:96005] " nobu
  17 siblings, 0 replies; 19+ messages in thread
From: shevegen @ 2019-11-04 21:32 UTC (permalink / raw)
  To: ruby-core

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é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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:95681] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2019-11-04 21:32 ` [ruby-core:95679] " shevegen
@ 2019-11-04 21:35 ` shevegen
  2019-11-28  4:19 ` [ruby-core:96005] " nobu
  17 siblings, 0 replies; 19+ messages in thread
From: shevegen @ 2019-11-04 21:35 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by shevegen (Robert A. Heiler).


Actually, after rereading what Jonathan wrote, he referred not to "true" values
per se, but as to whether "non nil values" are to be included. So perhaps I
misunderstood his comment. I think that filter still applies to the .select
and should return what matches to the given criterium, so from this point of
view I understand Jonathan's confusion. Either way I think it is best to 
define this clearly.

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

* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96005] [Ruby master Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map
       [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
                   ` (16 preceding siblings ...)
  2019-11-04 21:35 ` [ruby-core:95681] " shevegen
@ 2019-11-28  4:19 ` nobu
  17 siblings, 0 replies; 19+ messages in thread
From: nobu @ 2019-11-28  4:19 UTC (permalink / raw)
  To: ruby-core

Issue #15323 has been updated by nobu (Nobuyoshi Nakada).


It seems OK as the original proposal is same as the current behavior.

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

* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2019-11-28  4:20 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15323.20181120115943@ruby-lang.org>
2018-11-20 11:59 ` [ruby-core:89907] [Ruby trunk Feature#15323] [PATCH] Proposal: Add Enumerable#filter_map me
2018-11-20 14:29 ` [ruby-core:89908] " tonysunnymails
2018-11-20 17:07 ` [ruby-core:89912] " shevegen
2018-12-14 19:58 ` [ruby-core:90531] " nardonykolyszyn
2018-12-14 20:22   ` [ruby-core:90532] " oleynikov
2018-12-17  3:43 ` [ruby-core:90582] " matthew
2019-02-13  2:41 ` [ruby-core:91524] " shugo
2019-04-25  9:54 ` [ruby-core:92406] " me
2019-04-30 21:35 ` [ruby-core:92505] " grzegorz.jakubiak
2019-05-22  6:06 ` [ruby-core:92764] " matz
2019-05-23 15:46 ` [ruby-core:92802] " nobu
2019-10-06 19:16 ` [ruby-core:95248] [Ruby master " jonathan
2019-10-06 19:22 ` [ruby-core:95249] " eregontp
2019-10-06 20:43 ` [ruby-core:95251] " jonathan
2019-10-08 21:35 ` [ruby-core:95283] " eregontp
2019-10-11  2:34 ` [ruby-core:95300] " joshua.goodall
2019-11-04 21:32 ` [ruby-core:95679] " shevegen
2019-11-04 21:35 ` [ruby-core:95681] " shevegen
2019-11-28  4:19 ` [ruby-core:96005] " nobu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).