ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:89269] [Ruby trunk Feature#15198] Array#intersect?
       [not found] <redmine.issue-15198.20181003200703@ruby-lang.org>
@ 2018-10-03 20:07 ` c4am95
  2018-10-04  2:28 ` [ruby-core:89273] " shyouhei
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: c4am95 @ 2018-10-03 20:07 UTC (permalink / raw)
  To: ruby-core

Issue #15198 has been reported by c4am95 (Travis Hunter).

----------------------------------------
Feature #15198: Array#intersect?
https://bugs.ruby-lang.org/issues/15198

* Author: c4am95 (Travis Hunter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I frequently find myself needing to determine if two arrays intersect but not actually caring about the intersection, so I write code like:
~~~ ruby
(a1 & a2).any?
~~~

It would be nice to have an **intersect?** convenience method on **Array** to perform this query.

[ruby#1972: Add Array#intersect?](https://github.com/ruby/ruby/pull/1972)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:89273] [Ruby trunk Feature#15198] Array#intersect?
       [not found] <redmine.issue-15198.20181003200703@ruby-lang.org>
  2018-10-03 20:07 ` [ruby-core:89269] [Ruby trunk Feature#15198] Array#intersect? c4am95
@ 2018-10-04  2:28 ` shyouhei
  2018-10-05 14:01 ` [ruby-core:89287] " c4am95
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: shyouhei @ 2018-10-04  2:28 UTC (permalink / raw)
  To: ruby-core

Issue #15198 has been updated by shyouhei (Shyouhei Urabe).


- Interesting.  Can you share a bit more detail about your "if two arrays intersect but not actually caring about the intersection" use case?  For instance if you have open sourced such code, a URL for it helps us a lot.

- If you have zero interest to the intersection itself I think you can avoid creating the temporary array.

----------------------------------------
Feature #15198: Array#intersect?
https://bugs.ruby-lang.org/issues/15198#change-74297

* Author: c4am95 (Travis Hunter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I frequently find myself needing to determine if two arrays intersect but not actually caring about the intersection, so I write code like:
~~~ ruby
(a1 & a2).any?
~~~

It would be nice to have an **intersect?** convenience method on **Array** to perform this query.

[ruby#1972: Add Array#intersect?](https://github.com/ruby/ruby/pull/1972)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:89287] [Ruby trunk Feature#15198] Array#intersect?
       [not found] <redmine.issue-15198.20181003200703@ruby-lang.org>
  2018-10-03 20:07 ` [ruby-core:89269] [Ruby trunk Feature#15198] Array#intersect? c4am95
  2018-10-04  2:28 ` [ruby-core:89273] " shyouhei
@ 2018-10-05 14:01 ` c4am95
  2018-10-06 17:30 ` [ruby-core:89297] " shevegen
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: c4am95 @ 2018-10-05 14:01 UTC (permalink / raw)
  To: ruby-core

Issue #15198 has been updated by c4am95 (Travis Hunter).


The most recent example I encountered was authorizing a user in a Rails endpoint. Each user has a list of abilities, and each endpoint has a list of abilities that is authorized to perform the action. We just need to check if there is an intersection between the two lists.

I updated the PR to avoid creating the intermediate array.

----------------------------------------
Feature #15198: Array#intersect?
https://bugs.ruby-lang.org/issues/15198#change-74316

* Author: c4am95 (Travis Hunter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I frequently find myself needing to determine if two arrays intersect but not actually caring about the intersection, so I write code like:
~~~ ruby
(a1 & a2).any?
~~~

It would be nice to have an **intersect?** convenience method on **Array** to perform this query.

[ruby#1972: Add Array#intersect?](https://github.com/ruby/ruby/pull/1972)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:89297] [Ruby trunk Feature#15198] Array#intersect?
       [not found] <redmine.issue-15198.20181003200703@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-10-05 14:01 ` [ruby-core:89287] " c4am95
@ 2018-10-06 17:30 ` shevegen
  2018-10-07 23:19 ` [ruby-core:89309] " c4am95
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: shevegen @ 2018-10-06 17:30 UTC (permalink / raw)
  To: ruby-core

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


Demonstrated use cases helps the core team & matz assess on the usefulness of a proposed
change, which can help in accepting issue requests ultimately in the long run (if the
use case is considered sufficiently useful). :)

----------------------------------------
Feature #15198: Array#intersect?
https://bugs.ruby-lang.org/issues/15198#change-74331

* Author: c4am95 (Travis Hunter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I frequently find myself needing to determine if two arrays intersect but not actually caring about the intersection, so I write code like:
~~~ ruby
(a1 & a2).any?
~~~

It would be nice to have an **intersect?** convenience method on **Array** to perform this query.

[ruby#1972: Add Array#intersect?](https://github.com/ruby/ruby/pull/1972)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:89309] [Ruby trunk Feature#15198] Array#intersect?
       [not found] <redmine.issue-15198.20181003200703@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2018-10-06 17:30 ` [ruby-core:89297] " shevegen
@ 2018-10-07 23:19 ` c4am95
  2018-10-08 17:10 ` [ruby-core:89321] " c4am95
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: c4am95 @ 2018-10-07 23:19 UTC (permalink / raw)
  To: ruby-core

Issue #15198 has been updated by c4am95 (Travis Hunter).


I threw together a contrived example in a [gist](https://gist.github.com/travisofthenorth/eb2a68f5cd309dc7442ec4e1e55ae117) which is very similar to the use case I described. I have also run into numerous other situations where this functionality would have been useful.

I added some comments in the gist but I'll cross-post them here for reference:
> The current behavior creates an intermediate array for both intersection tests when the resulting array is clearly not needed. With the desired behavior, we could avoid creating the intermediate array and produce a faster best case runtime.

----------------------------------------
Feature #15198: Array#intersect?
https://bugs.ruby-lang.org/issues/15198#change-74338

* Author: c4am95 (Travis Hunter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I frequently find myself needing to determine if two arrays intersect but not actually caring about the intersection, so I write code like:
~~~ ruby
(a1 & a2).any?
~~~

It would be nice to have an **intersect?** convenience method on **Array** to perform this query.

[ruby#1972: Add Array#intersect?](https://github.com/ruby/ruby/pull/1972)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:89321] [Ruby trunk Feature#15198] Array#intersect?
       [not found] <redmine.issue-15198.20181003200703@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2018-10-07 23:19 ` [ruby-core:89309] " c4am95
@ 2018-10-08 17:10 ` c4am95
  2019-09-04 14:18 ` [ruby-core:94776] [Ruby master " daniel
  2019-10-23 17:58 ` [ruby-core:95508] " c4am95
  7 siblings, 0 replies; 8+ messages in thread
From: c4am95 @ 2018-10-08 17:10 UTC (permalink / raw)
  To: ruby-core

Issue #15198 has been updated by c4am95 (Travis Hunter).


It also seems like it comes up fairly commonly on stackoverflow/blogs:
https://stackoverflow.com/questions/2603895/how-can-i-check-if-a-ruby-array-includes-one-of-several-values
https://www.ruby-forum.com/t/find-if-an-array-has-any-element-present-in-another-array/166877
https://irb.rocks/comparison-arrays-ruby/
https://tosbourn.com/set-intersection-in-ruby/

----------------------------------------
Feature #15198: Array#intersect?
https://bugs.ruby-lang.org/issues/15198#change-74350

* Author: c4am95 (Travis Hunter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I frequently find myself needing to determine if two arrays intersect but not actually caring about the intersection, so I write code like:
~~~ ruby
(a1 & a2).any?
~~~

It would be nice to have an **intersect?** convenience method on **Array** to perform this query.

[ruby#1972: Add Array#intersect?](https://github.com/ruby/ruby/pull/1972)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:94776] [Ruby master Feature#15198] Array#intersect?
       [not found] <redmine.issue-15198.20181003200703@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2018-10-08 17:10 ` [ruby-core:89321] " c4am95
@ 2019-09-04 14:18 ` daniel
  2019-10-23 17:58 ` [ruby-core:95508] " c4am95
  7 siblings, 0 replies; 8+ messages in thread
From: daniel @ 2019-09-04 14:18 UTC (permalink / raw)
  To: ruby-core

Issue #15198 has been updated by Dan0042 (Daniel DeLorme).


It might make sense to use `ary1.to_set.intersect?(ary2)`. That way it makes explicit the fact that ary1 must be converted to a set. But `Set#intersect?` would have to support any Enumerable.

----------------------------------------
Feature #15198: Array#intersect?
https://bugs.ruby-lang.org/issues/15198#change-81394

* Author: c4am95 (Travis Hunter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I frequently find myself needing to determine if two arrays intersect but not actually caring about the intersection, so I write code like:
~~~ ruby
(a1 & a2).any?
~~~

It would be nice to have an **intersect?** convenience method on **Array** to perform this query.

[ruby#1972: Add Array#intersect?](https://github.com/ruby/ruby/pull/1972)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:95508] [Ruby master Feature#15198] Array#intersect?
       [not found] <redmine.issue-15198.20181003200703@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2019-09-04 14:18 ` [ruby-core:94776] [Ruby master " daniel
@ 2019-10-23 17:58 ` c4am95
  7 siblings, 0 replies; 8+ messages in thread
From: c4am95 @ 2019-10-23 17:58 UTC (permalink / raw)
  To: ruby-core

Issue #15198 has been updated by c4am95 (Travis Hunter).


I tried setting that up here: https://github.com/ruby/ruby/pull/2598

I ignored infinite ranges for now

----------------------------------------
Feature #15198: Array#intersect?
https://bugs.ruby-lang.org/issues/15198#change-82284

* Author: c4am95 (Travis Hunter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I frequently find myself needing to determine if two arrays intersect but not actually caring about the intersection, so I write code like:
~~~ ruby
(a1 & a2).any?
~~~

It would be nice to have an **intersect?** convenience method on **Array** to perform this query.

[ruby#1972: Add Array#intersect?](https://github.com/ruby/ruby/pull/1972)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-10-23 17:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15198.20181003200703@ruby-lang.org>
2018-10-03 20:07 ` [ruby-core:89269] [Ruby trunk Feature#15198] Array#intersect? c4am95
2018-10-04  2:28 ` [ruby-core:89273] " shyouhei
2018-10-05 14:01 ` [ruby-core:89287] " c4am95
2018-10-06 17:30 ` [ruby-core:89297] " shevegen
2018-10-07 23:19 ` [ruby-core:89309] " c4am95
2018-10-08 17:10 ` [ruby-core:89321] " c4am95
2019-09-04 14:18 ` [ruby-core:94776] [Ruby master " daniel
2019-10-23 17:58 ` [ruby-core:95508] " c4am95

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).