From: anamma06@... Date: 2018-05-24T00:06:33+00:00 Subject: [ruby-core:87246] [Ruby trunk Feature#14097] Add union and difference to Array Issue #14097 has been updated by ana06 (Ana Maria Martinez Gomez). @matz > I am not sure your real intention. Do you want mutating variation of or-operator? > Or just more readable alias of or-operator? Thanks for taking a look at the issue. What I am proposing is a new union method that it is an alias for `|` in the case of two arrays but that it is also more efficient in the case of more than two arrays. Exactly as it happens with `+` and `concat`. `concat`, apart from modifying the first array (which maybe shouldn't be the case) is more readable, but in the case on more than two arrays is more efficient as well. I also send a PR with a possible implementation: https://github.com/ruby/ruby/pull/1747 ---------------------------------------- Feature #14097: Add union and difference to Array https://bugs.ruby-lang.org/issues/14097#change-72235 * Author: ana06 (Ana Maria Martinez Gomez) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- 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: