Issue #14097 has been updated by ana06 (Ana Maria Martinez Gomez).


> The argument against the | operator could potentially apply to any operator. Most things are unclear until they are learned. Someone with no knowledge of English might find the | operator more clear than the union method.

Ruby is the language, which claims to have an elegant syntax that is natural to read and easy to write. And that's why it have readable method for operators. And that's what people love about Ruby. But I am not saying that we should remove the operator, so you can keep using it. ;)

> 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.

> 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.

I am sorry, but 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.

----------------------------------------
Bug #14097: Add union and difference to Array
https://bugs.ruby-lang.org/issues/14097#change-67824

* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>