From: anamma06@... Date: 2017-11-13T15:22:34+00:00 Subject: [ruby-core:83755] [Ruby trunk Bug#14097] Add union and difference to Array Issue #14097 has been updated by ana06 (Ana Maria Martinez Gomez). @jeremyevans0 > The array class already has a union operator (|) which returns a new array, and in combination with replace you can easily build union. union doesn't seem a common enough need to warrant adding as a separate core method. Yes, a operator that is not clear for many people. I think Ruby deserve something more readable and elegant. Moreover, `union` would allow to make the union of more than 2 arrays at the same time in a much more efficient way than applying `|` several times. So it is not only an "stetic" change, it is also a performance improvement. I am not sure what to mean what replace to build a union. Can you please elaborate? ---------------------------------------- Bug #14097: Add union and difference to Array https://bugs.ruby-lang.org/issues/14097#change-67793 * 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: