From: david.n.arnold@... Date: 2017-08-08T15:31:07+00:00 Subject: [ruby-core:82281] [Ruby trunk Feature#13784] Add Enumerable#filter as an alias of Enumerable#select Issue #13784 has been updated by davidarnold (David Arnold). > I understand that it is beneficial for people familiar with other languages that have a "filter" function like this, but I believe "filter" is confusing for people without that familiarity. The great thing is that with aliases, you can choose to use whichever one you like better. If select, reject, or find_all makes the most sense, then go ahead and keep using it. Why not add something that is greatly beneficial for people with experience in any of those 15 other languages? The documentation would make it clear what it does. > When I mentioned this ticket to my coworker, his initial reaction was that "filter" would be an alias for "reject". I suppose depending on your background, anything could be confusing. For example I would have guessed that select was map (since that exactly what it means in SQL and LINQ) and that collect would have been reduce (since you are going through the list and collecting them into a single value), and inject, well... I wouldn't have had any clue what that meant without reading the docs. Which goes back to the point about documentation. Who (aside from Smalltalk developers) would have known what collect, select, and inject meant without reading the docs? But we read it, said "ok", and used them correctly. If the documentation for filter states that it "returns an array containing all elements of enum for which the given block returns a true value" then that is what it does. ---------------------------------------- Feature #13784: Add Enumerable#filter as an alias of Enumerable#select https://bugs.ruby-lang.org/issues/13784#change-66069 * 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: