ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: c4am95@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:89309] [Ruby trunk Feature#15198] Array#intersect?
Date: Sun, 07 Oct 2018 23:19:52 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-74338.20181007231951.6533d3935f925a3c@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15198.20181003200703@ruby-lang.org

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/

  parent reply	other threads:[~2018-10-07 23:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 ` c4am95 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-74338.20181007231951.6533d3935f925a3c@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).