From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.1 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 20B4F1F97E for ; Sun, 7 Oct 2018 23:20:01 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C3602120CA1; Mon, 8 Oct 2018 08:19:58 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 4A9C212098B for ; Mon, 8 Oct 2018 08:19:56 +0900 (JST) Received: by filter0079p3iad2.sendgrid.net with SMTP id filter0079p3iad2-12125-5BBA9498-6 2018-10-07 23:19:52.216272383 +0000 UTC m=+174955.284805032 Received: from herokuapp.com (ec2-54-159-188-159.compute-1.amazonaws.com [54.159.188.159]) by ismtpd0024p1mdw1.sendgrid.net (SG) with ESMTP id 7o01Fey0S-KS-2F7iI24lg for ; Sun, 07 Oct 2018 23:19:51.905 +0000 (UTC) Date: Sun, 07 Oct 2018 23:19:52 +0000 (UTC) From: c4am95@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 64702 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15198 X-Redmine-Issue-Author: c4am95 X-Redmine-Sender: c4am95 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4BNjFja00B3NFwwl4FO6I8zwRJDRSN+phknK +wgozNAKQ2plviqQ67Maf27sFmszX+soFie4qL8ucsZ+HK2cHwQ3m+LebpviPA5gIeCEp39OuvZyPW 3K9DtjcK79ilfcWHRhxJ+j51s+LEV1jw2/Xm X-ML-Name: ruby-core X-Mail-Count: 89309 Subject: [ruby-core:89309] [Ruby trunk Feature#15198] Array#intersect? X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "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/