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=-3.6 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham 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 546F11F803 for ; Thu, 10 Jan 2019 08:30:52 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 41C2512101A; Thu, 10 Jan 2019 17:30:50 +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 53F6C120F0F for ; Thu, 10 Jan 2019 17:30:48 +0900 (JST) Received: by filter0145p3mdw1.sendgrid.net with SMTP id filter0145p3mdw1-19541-5C3702B4-3F 2019-01-10 08:30:44.754850727 +0000 UTC m=+203950.810173901 Received: from herokuapp.com (ec2-54-226-205-145.compute-1.amazonaws.com [54.226.205.145]) by ismtpd0042p1mdw1.sendgrid.net (SG) with ESMTP id 62ZnaxT8Qz6rV8WFjPOhfg for ; Thu, 10 Jan 2019 08:30:44.621 +0000 (UTC) Date: Thu, 10 Jan 2019 08:30:46 +0000 (UTC) From: knu@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66417 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 6240 X-Redmine-Issue-Author: marcandre X-Redmine-Issue-Assignee: matz X-Redmine-Sender: knu 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS4onIVmxNNetsxbzKIygLQ2gsVkusba/5+WpV WFwp5wqo2c77EpnVEulYbO6/cQPFVxXfD02nnauWTY0LQS+v/TVvRI/XxeVF/5Z4PTgfMzOzQ4R7cB YgU+ReBotRBAkHnQACpeIL58yIb1mIy3U6lCXz/UInSe1srfmH7tU+o1lg== X-ML-Name: ruby-core X-Mail-Count: 90982 Subject: [ruby-core:90982] [Ruby trunk Feature#6240] Enumerable#drop with negative argument 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 #6240 has been updated by knu (Akinori MUSHA). Using an existing feature, `[1,2,3,4,5].lazy.drop(-n)` could be written as `[1,2,3,4,5].each_cons(n+1).lazy.map(&:first)`. Enumerable#each_cons does not use a circular buffer, though. (It currently uses push & shift) ---------------------------------------- Feature #6240: Enumerable#drop with negative argument https://bugs.ruby-lang.org/issues/6240#change-76199 * Author: marcandre (Marc-Andre Lafortune) * Status: Feedback * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- Currently, Enumerable#drop works only for non-negative arguments. It could be extended so that negative arguments means dropping from the end: [:hello, :world].drop(-1) # => [:hello] This could especially be interesting for `Lazy#drop`, which would keep a circular buffer of elements before yielding them. (1..6).lazy.drop(-3).each{|x| puts x} # -> prints 1, 2 and 3 Thoughts? -- https://bugs.ruby-lang.org/