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.8 required=3.0 tests=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 7EA7A1F4C0 for ; Wed, 30 Oct 2019 19:30:57 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 6D4911209F9; Thu, 31 Oct 2019 04:30:47 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id AE2A71209F3 for ; Thu, 31 Oct 2019 04:30:44 +0900 (JST) Received: by filter0084p3las1.sendgrid.net with SMTP id filter0084p3las1-19773-5DB9E4E7-34 2019-10-30 19:30:47.36225971 +0000 UTC m=+156231.361351461 Received: from herokuapp.com (unknown [18.215.166.206]) by ismtpd0036p1mdw1.sendgrid.net (SG) with ESMTP id sWsGZHUxSry-4kTIa0Rw1Q for ; Wed, 30 Oct 2019 19:30:47.185 +0000 (UTC) Date: Wed, 30 Oct 2019 19:30:47 +0000 (UTC) From: keystonelemur@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71185 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15123 X-Redmine-Issue-Author: printercu X-Redmine-Issue-Assignee: matz X-Redmine-Sender: baweaver 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?XlD0LGPYDDjb=2FA1CQKGKXgvLTTlhHMIrQD1g5Sx7EbKrBfPIhNONDSrvOGAwDA?= =?us-ascii?Q?8A=2FOqNB1FI4mYPbgDVNvtp1ZtNXIgPfGVFi+9NB?= =?us-ascii?Q?rxkgcGvejshu1YlBNXG7lbdEok7d1YNCcKeNaUH?= =?us-ascii?Q?vlASZ0aU3TzhVJuHxeiEM=2FTJTAXnq1VXuJBLPbh?= =?us-ascii?Q?8Rrmot6Qm6fTS02n+BQuG1hSBzW4=2FMY0UyQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95592 Subject: [ruby-core:95592] [Ruby master Feature#15123] Enumerable#compact proposal 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 #15123 has been updated by baweaver (Brandon Weaver). @matz: Its presence in Array and Hash make it more of a common interface that I could see being defined for Enumerable in general, though the immediate usecases are around Lazy. As mentioned above, sometimes one wants to use Enumerators directly or returns one from an Enumerable method which can cause some conflicts of available methods. I believe it could be considered surprising that `compact` does not necessarily work with all collection-like types. ---------------------------------------- Feature #15123: Enumerable#compact proposal https://bugs.ruby-lang.org/issues/15123#change-82382 * Author: printercu (Max Melentiev) * Status: Feedback * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- Hi! While Enumerable does not provide `#compact` method, it requires changing code in some cases to substitute array with enumerator. For example, to reduce memory usage it's usual to change `large_array.map { to_heavy_object }.chained_methods` to `large_array.lazy...`. However if `chained_methods` contains `compact`, this change will fail. Replacing `compact` with `reject(&:nil?)` fixes it. What do you think about adding `#compact` to Enumerable? -- https://bugs.ruby-lang.org/