From: duerst@... Date: 2017-08-09T04:53:00+00:00 Subject: [ruby-core:82290] [Ruby trunk Feature#13784] Add Enumerable#filter as an alias of Enumerable#select Issue #13784 has been updated by duerst (Martin D��rst). I think adding `filter` as an alias of `select` is a good idea, because indeed many languages use that name. As for confusability with `reject`, everybody who already has seen `filter` in another language will assume it's an alias for `select`, not for `reject`. Those who haven't will very quickly learn that when they use it the first time. davidarnold (David Arnold) wrote: > > 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'. > So my guess is that only Hash#select got the new behavior since it already existed in hash.c whereas find_all was only defined in Enumerable. Assuming this feature is approved, I will open a separate bug to start a discussion about whether the discrepancy is intentional or if Hash#find_all should be changed to match Hash#select. > > For the purpose of this feature request, I would leave the filter == find_all behavior the same. If the decision in the bug report is that Hash#find_all should match Hash#select, then an alias can be added for both Hash#find_all and Hash#filter. No, please fix your bug. Your proposal and its title are explicitly to make `filter` an alias of `select`. Please don't make that dependent on another, separate 'bug'. It would be really inconvenient if we had to say "`filter` is an alias of `select`, except for `Hash`, where it's an alias of `find_all`. ---------------------------------------- Feature #13784: Add Enumerable#filter as an alias of Enumerable#select https://bugs.ruby-lang.org/issues/13784#change-66076 * 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: