ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: knu@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:90982] [Ruby trunk Feature#6240] Enumerable#drop with negative argument
Date: Thu, 10 Jan 2019 08:30:46 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-76199.20190110083044.9c2d942fe0f94f30@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-6240.20120401055741@ruby-lang.org

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/

  parent reply	other threads:[~2019-01-10  8:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-31 20:57 [ruby-core:44028] [ruby-trunk - Feature #6240][Open] Enumerable#drop with negative argument marcandre (Marc-Andre Lafortune)
2012-04-01  0:05 ` [ruby-core:44030] [ruby-trunk - Feature #6240] " shugo (Shugo Maeda)
2012-04-01 23:38 ` [ruby-core:44047] " marcandre (Marc-Andre Lafortune)
2012-04-02  1:41 ` [ruby-core:44051] " shugo (Shugo Maeda)
2012-04-02 13:59 ` [ruby-core:44069] [ruby-trunk - Feature #6240][Assigned] " mame (Yusuke Endoh)
2012-10-25  8:48 ` [ruby-core:48242] [ruby-trunk - Feature #6240] " yhara (Yutaka HARA)
2019-01-10  8:30 ` knu [this message]
2019-01-10 23:07 ` [ruby-core:91006] [Ruby trunk Feature#6240][Closed] " ruby-core

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-76199.20190110083044.9c2d942fe0f94f30@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).