From: anamma06@... Date: 2018-08-28T08:22:07+00:00 Subject: [ruby-core:88709] [Ruby trunk Feature#14097] Add union and difference to Array Issue #14097 has been updated by ana06 (Ana Maria Martinez Gomez). @Student, as I just answered in the [PR](https://github.com/ruby/ruby/pull/1747#issuecomment-416494207) about the same concern, I'll answer here to: > I think there are some uses of case. First, it could be that you have an array in your application, would it be worthwhile to convert it to set just to be able to do a union? Second, what happen if you want to add the elements of an array to another array only if they were not already there but keeping the order? you can not do this with a set. Third, what if after the union you want to apply a method in the Array class that is not in the Set class (like for example `sort_by`)? ---------------------------------------- Feature #14097: Add union and difference to Array https://bugs.ruby-lang.org/issues/14097#change-73766 * Author: ana06 (Ana Maria Martinez Gomez) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * 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: