Issue #15976 has been updated by shevegen (Robert A. Heiler).


To me the name of the method appears to make sense and I am slightly in 
favour of the suggestion. I can not say how useful this method would be
in general, though, mostly because I think I needed to do something
such as (array1 & array2).any? perhaps only once or twice in a long 
time in my own code; but even then I think this might be a useful
proposal and a name that makes sense (to me at the least).

----------------------------------------
Feature #15976: Add Array#overlap? for whether the intersection of 2 arrays is non empty?
https://bugs.ruby-lang.org/issues/15976#change-79047

* Author: fcheung (Frederick Cheung)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
This is semantically equivalent to `(ary1 & ary2).any?`, but more efficient and makes the intent more obvious.

For example bundler [checks]( https://github.com/ruby/ruby/blob/master/lib/bundler/runtime.rb#L61 ) whether the list of requested groups and the list of groups for a dependency has any overlap - it doesn't care what the overlap is, as long as it is non empty

In my personal projects we've found this to be a bottleneck when the arrays are large and where intersections are likely - `(ary1 & ary2).any`? keeps searching for all of the intersection even after we've found the first one, & creates extra garbage because of the intermediate array.

See https://github.com/ruby/ruby/pull/2260

---Files--------------------------------
2260.patch (6.58 KB)


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