From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.7 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id C8A721F454 for ; Mon, 11 Nov 2019 15:37:28 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id D41F4120A5F; Tue, 12 Nov 2019 00:37:13 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 1A253120A50 for ; Tue, 12 Nov 2019 00:37:11 +0900 (JST) Received: by filter0091p3las1.sendgrid.net with SMTP id filter0091p3las1-21002-5DC98026-C6 2019-11-11 15:37:10.710854159 +0000 UTC m=+324015.042289825 Received: from herokuapp.com (unknown [35.171.185.2]) by ismtpd0036p1iad1.sendgrid.net (SG) with ESMTP id J8ustv8-R7CDOBH3h867IQ for ; Mon, 11 Nov 2019 15:37:10.556 +0000 (UTC) Date: Mon, 11 Nov 2019 15:37:10 +0000 (UTC) From: non.dmitriy@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71419 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16341 X-Redmine-Issue-Author: Nondv X-Redmine-Sender: Nondv 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: =?us-ascii?Q?EtUBU5pNPGGF695WqpG6VxCA85Kr9QQx+VRnpZEtiFe4=2FVScDs+rXQwrpQhaji?= =?us-ascii?Q?gltwnTRAH9wBmzYqIERr11YW1bQVmxsT3SLn4BH?= =?us-ascii?Q?NOTKtu=2FLH9hFwPnN59mYZkL20Tys+KH6O2MGKfP?= =?us-ascii?Q?mUimazXLnS6KZ2grHtI9=2FGt+0Rsx1bInwNJGHxI?= =?us-ascii?Q?Rh47AJjS8oDPSkTYGIIl2nJsE74ZJ5Fd1pg=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95794 Subject: [ruby-core:95794] [Ruby master Feature#16341] Proposal: Set#to_proc 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 #16341 has been updated by Nondv (Dmitry Non). Well, to be fair, this change is just nice-to-have sugar. I don't expect it to become a thing. I guess for now the best way to do that is: ```ruby pets.count { |x| dogs.include?(x) } # or pets.count(&dogs.method(:include?)) ``` They both are "more clear than value-object-suddenly-becoming-procs". But having implicit conversion would be just a nice feature to make code more compact and expressive (MHO). Clojure treats sets as functions, btw: ```clojure (def dogs #{:labrador :husky :bullterrier :corgi}) (count (filter dogs [:parrot :labrador :goldfish :husky :labrador :turtle])) ``` ---------------------------------------- Feature #16341: Proposal: Set#to_proc https://bugs.ruby-lang.org/issues/16341#change-82615 * Author: Nondv (Dmitry Non) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- ``` ruby class Set def to_proc -> (x) { include?(x) } # or method(:include?).to_proc end end ``` Usage: ```ruby require 'set' banned_numbers = Set[0, 5, 7, 9] (1..10).reject(&banned_numbers) # ===> [1, 2, 3, 4, 6, 8, 10] ``` -- https://bugs.ruby-lang.org/