From: merch-redmine@... Date: 2017-11-15T15:54:03+00:00 Subject: [ruby-core:83787] [Ruby trunk Bug#14097] Add union and difference to Array Issue #14097 has been updated by jeremyevans0 (Jeremy Evans). ana06 (Ana Maria Martinez Gomez) wrote: > > You could build union without a nested application of |. No doubt you could get the maximum performance by implementing it in C, but I don't believe the cost of maintaining such code is worth it, considering how often it is used. > > It is some really simple code. And I will implement it, why do you care about the effort to do it? It is someone else effort, who is really happy to do it. I care because once it is added, it is impossible to remove without breaking backwards compatibility. This is not a one time cost of initial implementation, it's a perpetual maintenance cost. I'm not in favor of adding methods to the core classes simply because they are useful in certain cases. If we added every method to the core classes that was useful in specific cases, we'd eventually have thousands of methods in each core class. > > In similar cases in the past, the recommendation has often been to build the functionality as a gem, and if the gem gets popular and widely used, then it can be considered for inclusion in core. > > What I want is to provide an efficient union of several arrays, that need to be implemented in C. Implementing this in a Ruby gem makes no point at all. It appears you may not be aware that plenty of ruby gems are implemented in C using ruby's C-API and have same performance as if they were part of ruby core. ---------------------------------------- Bug #14097: Add union and difference to Array https://bugs.ruby-lang.org/issues/14097#change-67825 * Author: ana06 (Ana Maria Martinez Gomez) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- Currently there is a concat method in ruby which does the same as +, but modifying the object. We could introduce a union and difference methods, which would be the equivalent for the `|` and `-` operators. This operators are normally less used due to lack of readability and expressivity. You end seeing thinks like: ``` array.concat(array2).uniq! ``` just because it is more readable. When it could be written like: ``` array |= array2 ``` But, as this is not clear for some people, the new method will solve this problem: ``` array.union(array2) ``` And now this is clean and readable, as everybody expect from Ruby, the language focused on simplicity and productivity. ;) Can I send a PR? :) -- https://bugs.ruby-lang.org/ Unsubscribe: