From: Eli Sadoff Date: 2017-08-08T22:01:37+00:00 Subject: [ruby-core:82285] Re: [Ruby trunk Feature#13784] Add Enumerable#filter as an alias of Enumerable#select --===============0066441929== Content-Type: multipart/alternative; boundary="f403045e22a619d7280556451cfe" --f403045e22a619d7280556451cfe Content-Type: text/plain; charset="UTF-8" I think if select and filter are aliases on Enumerable they should also be aliases on Hash. I think it could be quite confusing and almost seems like it violates some rule to override a method but not re-alias in the child class to the overriddden method unless there's a very specific reason why. On Tue, Aug 8, 2017 at 17:35 wrote: > Issue #13784 has been updated by adp90 (Alexander Patrick). > > > A potential concern could be language bloat. Having too many aliases for > the same methods could be confusing. > I was curious which underlying methods have the most aliases, so I wrote a > quick script to look through the code. > > [C method name, number of aliases] > ------------------- > ["lazy_super", 5] > ["rb_hash_has_key", 4] > ["proc_call", 4] > ["wmap_has_key", 3] > ["time_utc_offset", 3] > > All other methods have 1 or 2 aliases. Furthermore, lazy_super (chunk and > slice methods) and proc_call aliases each do different things so they don't > really count. > > Filter would be enum_find_all's third alias. That could be fine, but I'm > interested in others' thoughts on this. > > On another note, there is a small difference between 'find_all' and > 'select', due to 'select' being overridden for hashes. ( > https://stackoverflow.com/questions/20999192/is-find-all-and-select-the-same-thing > ) > It might be inconsequential, but the 'filter' method in my pull request > acts more like 'find_all'. > > hash = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6} > > hash.select { |k,v| v.even? } > => {:b=>2, :d=>4, :f=>6} > > hash.find_all { |k,v| v.even? } > => [[:b, 2], [:d, 4], [:f, 6]] > > hash.filter { |k,v| v.even? } > => [[:b, 2], [:d, 4], [:f, 6]] > > ---------------------------------------- > Feature #13784: Add Enumerable#filter as an alias of Enumerable#select > https://bugs.ruby-lang.org/issues/13784#change-66072 > > * Author: davidarnold (David Arnold) > * Status: Open > * Priority: Normal > * Assignee: > * Target version: > ---------------------------------------- > Ruby has a full set of functional tools in the Enumerable module under the > "-ect" methods (viz. collect, select, inject). However the usual industry > terms for these are map, filter, and reduce. > > For example, Swift, Python, and ECMAScript all use the names map, filter, > and reduce to describe these methods. Also, this language independent MIT > course uses map, filter and reduce: > http://web.mit.edu/6.005/www/fa15/classes/25-map-filter-reduce/ > > Ruby has aliases for map and reduce, but filter is noticeably absent. > This feature request is simply to add an alias to Enumerable for filter. > This will ease the transition of developers from other languages to Ruby. > > Desired behavior: > > [:foo, :bar].filter { |x| x == :foo } # => [:foo] > > Current behavior: > > [:foo, :bar].filter { |x| x == :foo } # NoMethodError: undefined method > `filter' > > > > -- > https://bugs.ruby-lang.org/ > > Unsubscribe: > > --f403045e22a619d7280556451cfe Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I think if select and filter are aliases on Enumerab= le they should also be aliases on Hash. I think it could be quite confusing= and almost seems like it violates some rule to override a method but not r= e-alias in the child class to the overriddden method unless there's a v= ery specific reason why.=C2=A0

On = Tue, Aug 8, 2017 at 17:35 <adp90@case.= edu> wrote:
Issue #13784 has= been updated by adp90 (Alexander Patrick).


A potential concern could be language bloat. Having too many aliases for th= e same methods could be confusing.
I was curious which underlying methods have the most aliases, so I wrote a = quick script to look through the code.

[C method name, number of aliases]
-------------------
["lazy_super", 5]
["rb_hash_has_key", 4]
["proc_call", 4]
["wmap_has_key", 3]
["time_utc_offset", 3]

All other methods have 1 or 2 aliases. Furthermore, lazy_super (chunk and s= lice methods) and proc_call aliases each do different things so they don= 9;t really count.

Filter would be enum_find_all's third alias. That could be fine, but I&= #39;m interested in others' thoughts on this.

On another note, there is a small difference between 'find_all' and= 'select', due to 'select' being overridden for hashes. (https://stackoverflo= w.com/questions/20999192/is-find-all-and-select-the-same-thing)
It might be inconsequential, but the 'filter' method in my pull req= uest acts more like 'find_all'.

hash =3D {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}

hash.select { |k,v| v.even? }
=3D> {:b=3D>2, :d=3D>4, :f=3D>6}

hash.find_all { |k,v| v.even? }
=3D> [[:b, 2], [:d, 4], [:f, 6]]

hash.filter { |k,v| v.even? }
=3D> [[:b, 2], [:d, 4], [:f, 6]]

----------------------------------------
Feature #13784: Add Enumerable#filter as an alias of Enumerable#select
https://bugs.ruby-lang.org/issues/13784#change-6= 6072

* Author: davidarnold (David Arnold)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Ruby has a full set of functional tools in the Enumerable module under the = "-ect" methods (viz. collect, select, inject).=C2=A0 However the = usual industry terms for these are map, filter, and reduce.

For example, Swift, Python, and ECMAScript all use the names map, filter, a= nd reduce to describe these methods.=C2=A0 Also, this language independent = MIT course uses map, filter and reduce: http://web.mit.edu/6.005/www/fa15/classes/25-map-filter-reduce/

Ruby has aliases for map and reduce, but filter is noticeably absent.=C2=A0= This feature request is simply to add an alias to Enumerable for filter.= =C2=A0 This will ease the transition of developers from other languages to = Ruby.

Desired behavior:

[:foo, :bar].filter { |x| x =3D=3D :foo } # =3D> [:foo]

Current behavior:

[:foo, :bar].filter { |x| x =3D=3D :foo } # NoMethodError: undefined method= `filter'



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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=3Dunsubscribe= >
<http://lists.ruby-lang.org/cgi-bin/m= ailman/options/ruby-core>
--f403045e22a619d7280556451cfe-- --===============0066441929== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============0066441929==--