From: adp90@... Date: 2017-08-08T21:34:52+00:00 Subject: [ruby-core:82284] [Ruby trunk Feature#13784] Add Enumerable#filter as an alias of Enumerable#select 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: