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.2 required=3.0 tests=AWL,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 2891D1F404 for ; Sat, 15 Sep 2018 07:46:10 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 19F54120A04; Sat, 15 Sep 2018 16:46:07 +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 473171209F0 for ; Sat, 15 Sep 2018 16:46:04 +0900 (JST) Received: by filter0089p3las1.sendgrid.net with SMTP id filter0089p3las1-25261-5B9CB8B8-B 2018-09-15 07:46:00.389916197 +0000 UTC m=+31979.549302759 Received: from herokuapp.com (ec2-54-166-193-109.compute-1.amazonaws.com [54.166.193.109]) by ismtpd0039p1mdw1.sendgrid.net (SG) with ESMTP id bRmAoX9IQv63jhLbEoycnQ Sat, 15 Sep 2018 07:46:00.107 +0000 (UTC) Date: Sat, 15 Sep 2018 07:46:02 +0000 (UTC) From: eregontp@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 64419 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15123 X-Redmine-Issue-Author: printercu X-Redmine-Issue-Assignee: matz X-Redmine-Sender: Eregon 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5PKvwhzAjAH7MF2Xn1eBe+GQDyZ1bIdSh5qZ fWow3VVkGrMOR2XgoQ9lAN9xAPWlShzLBPJ+eidX58e1aE6ggAz/PSqAVr2uqR2YRBEt2s/MBJ8zOm NG1nl4y/CcoXrrAvl6iTjChpEsOlOizUu+BuV2TTk1I+fY03TBLQlpbiBw== X-ML-Name: ruby-core X-Mail-Count: 89026 Subject: [ruby-core:89026] [Ruby trunk Bug#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 Eregon (Benoit Daloze). marcandre (Marc-Andre Lafortune) wrote: > Also `compact` is roughly `select(&:itself)`, not `reject(&:nil?)` which would wrongly keep `false`. No, #compact only removes `nil`: `["a" ,false ,nil].compact` => `["a", false]`. ---------------------------------------- Bug #15123: Enumerable#compact proposal https://bugs.ruby-lang.org/issues/15123#change-74051 * Author: printercu (Max Melentiev) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: * ruby -v: * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- 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/