ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:61030] [ruby-trunk - Feature #9557] [Open] Enumerator#next and Enumerator#peek with argument
       [not found] <redmine.issue-9557.20140223091418@ruby-lang.org>
@ 2014-02-23  9:14 ` sawadatsuyoshi
  2014-02-23 17:13 ` [ruby-core:61033] [ruby-trunk - Feature #9557] " matz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: sawadatsuyoshi @ 2014-02-23  9:14 UTC (permalink / raw
  To: ruby-core

Issue #9557 has been reported by Tsuyoshi Sawada.

----------------------------------------
Feature #9557: Enumerator#next and Enumerator#peek with argument
https://bugs.ruby-lang.org/issues/9557

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
It often happens that I want to move the current index of an enumerator by some arbitrary number `n`. `Enumerator#feed` takes the element as the argument, but that cannot be used if the enumerator has duplicate elements, or when I do not have information of a particular element to choose but just want to increment the index by some number. `Enumerator#next`, on the other hand, has a fixed value `1` to be incremented. It would be convenient if `Enumerator#next` takes an optional argument that represents the difference of the index to be incremented. The argument can be understood to be defaulted to `1` when absent.

Also, I often want to look not necessarily the current position, but some position away. It would be good if `Enumerator#peek` takes an optional argument that represents the positional difference to be peeked. The argument can be understood to be defaulted to `0` when absent.

    enum = [0, 1, 2, 3, 4, 5, 6, 7, 8].to_enum
    enum.peek    # => 0
    enum.peek(0) # => 0
    enum.peek(1) # => 1
    enum.peek    # => 0
    enum.next    # => 0
    enum.next(1) # => 1
    enum.next(2) # => 2
    enum.peek    # => 4
    enum.peek(0) # => 4
    enum.peek(1) # => 5
    enum.peek    # => 4
    enum.next    # => 4
    enum.next(1) # => 5
    enum.next(2) # => 6
    peek         # => 8




-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:61033] [ruby-trunk - Feature #9557] Enumerator#next and Enumerator#peek with argument
       [not found] <redmine.issue-9557.20140223091418@ruby-lang.org>
  2014-02-23  9:14 ` [ruby-core:61030] [ruby-trunk - Feature #9557] [Open] Enumerator#next and Enumerator#peek with argument sawadatsuyoshi
@ 2014-02-23 17:13 ` matz
  2014-02-23 18:41 ` [ruby-core:61034] " sawadatsuyoshi
  2014-04-11 19:00 ` [ruby-core:61992] " transfire
  3 siblings, 0 replies; 4+ messages in thread
From: matz @ 2014-02-23 17:13 UTC (permalink / raw
  To: ruby-core

Issue #9557 has been updated by Yukihiro Matsumoto.


Do you mean peek and next to take *index* as an optional argument?
Some enumerators cannot be rewinded thus it's impossible to index.
If you mean skip not index, some enumerators cannot be peek further elements without modifying the position.

Besides that your description does not fully explain the behavior in your example.
Maybe the example need to be fixed.

Matz.


----------------------------------------
Feature #9557: Enumerator#next and Enumerator#peek with argument
https://bugs.ruby-lang.org/issues/9557#change-45438

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
It often happens that I want to move the current index of an enumerator by some arbitrary number `n`. `Enumerator#feed` takes the element as the argument, but that cannot be used if the enumerator has duplicate elements, or when I do not have information of a particular element to choose but just want to increment the index by some number. `Enumerator#next`, on the other hand, has a fixed value `1` to be incremented. It would be convenient if `Enumerator#next` takes an optional argument that represents the difference of the index to be incremented. The argument can be understood to be defaulted to `1` when absent.

Also, I often want to look not necessarily the current position, but some position away. It would be good if `Enumerator#peek` takes an optional argument that represents the positional difference to be peeked. The argument can be understood to be defaulted to `0` when absent.

    enum = [0, 1, 2, 3, 4, 5, 6, 7, 8].to_enum
    enum.peek    # => 0
    enum.peek(0) # => 0
    enum.peek(1) # => 1
    enum.peek    # => 0
    enum.next    # => 0
    enum.next(1) # => 1
    enum.next(2) # => 2
    enum.peek    # => 4
    enum.peek(0) # => 4
    enum.peek(1) # => 5
    enum.peek    # => 4
    enum.next    # => 4
    enum.next(1) # => 5
    enum.next(2) # => 6
    peek         # => 8




-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:61034] [ruby-trunk - Feature #9557] Enumerator#next and Enumerator#peek with argument
       [not found] <redmine.issue-9557.20140223091418@ruby-lang.org>
  2014-02-23  9:14 ` [ruby-core:61030] [ruby-trunk - Feature #9557] [Open] Enumerator#next and Enumerator#peek with argument sawadatsuyoshi
  2014-02-23 17:13 ` [ruby-core:61033] [ruby-trunk - Feature #9557] " matz
@ 2014-02-23 18:41 ` sawadatsuyoshi
  2014-04-11 19:00 ` [ruby-core:61992] " transfire
  3 siblings, 0 replies; 4+ messages in thread
From: sawadatsuyoshi @ 2014-02-23 18:41 UTC (permalink / raw
  To: ruby-core

Issue #9557 has been updated by Tsuyoshi Sawada.


> Do you mean peek and next to take index as an optional argument?

No, for `peek`, I mean the difference between the current position. So if the current position's index is `i`, then `peek(d)` looks at the element at index `i + d`.

And for `take`, my understanding is that, supposing the current index is `i`, then `take` reads whatever at position `i` and then increments the index to `i + 1`. My proposal is that when `take(d)` is given, increment the index to `i + d` instead of `i + 1` after it reads at `i`.

> Some enumerators cannot be rewinded thus it's impossible to index.
> If you mean skip not index, some enumerators cannot be peek further elements without modifying the position.

I see. Then I would like to ask this feature just for subset of enumerators, those that respond to `rewind`.

----------------------------------------
Feature #9557: Enumerator#next and Enumerator#peek with argument
https://bugs.ruby-lang.org/issues/9557#change-45439

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
It often happens that I want to move the current index of an enumerator by some arbitrary number `n`. `Enumerator#feed` takes the element as the argument, but that cannot be used if the enumerator has duplicate elements, or when I do not have information of a particular element to choose but just want to increment the index by some number. `Enumerator#next`, on the other hand, has a fixed value `1` to be incremented. It would be convenient if `Enumerator#next` takes an optional argument that represents the difference of the index to be incremented. The argument can be understood to be defaulted to `1` when absent.

Also, I often want to look not necessarily the current position, but some position away. It would be good if `Enumerator#peek` takes an optional argument that represents the positional difference to be peeked. The argument can be understood to be defaulted to `0` when absent.

    enum = [0, 1, 2, 3, 4, 5, 6, 7, 8].to_enum
    enum.peek    # => 0
    enum.peek(0) # => 0
    enum.peek(1) # => 1
    enum.peek    # => 0
    enum.next    # => 0
    enum.next(1) # => 1
    enum.next(2) # => 2
    enum.peek    # => 4
    enum.peek(0) # => 4
    enum.peek(1) # => 5
    enum.peek    # => 4
    enum.next    # => 4
    enum.next(1) # => 5
    enum.next(2) # => 6
    peek         # => 8




-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:61992] [ruby-trunk - Feature #9557] Enumerator#next and Enumerator#peek with argument
       [not found] <redmine.issue-9557.20140223091418@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2014-02-23 18:41 ` [ruby-core:61034] " sawadatsuyoshi
@ 2014-04-11 19:00 ` transfire
  3 siblings, 0 replies; 4+ messages in thread
From: transfire @ 2014-04-11 19:00 UTC (permalink / raw
  To: ruby-core

Issue #9557 has been updated by Thomas Sawyer.


Such features might benefit from an Indexable mixin.

----------------------------------------
Feature #9557: Enumerator#next and Enumerator#peek with argument
https://bugs.ruby-lang.org/issues/9557#change-46183

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
It often happens that I want to move the current index of an enumerator by some arbitrary number `n`. `Enumerator#feed` takes the element as the argument, but that cannot be used if the enumerator has duplicate elements, or when I do not have information of a particular element to choose but just want to increment the index by some number. `Enumerator#next`, on the other hand, has a fixed value `1` to be incremented. It would be convenient if `Enumerator#next` takes an optional argument that represents the difference of the index to be incremented. The argument can be understood to be defaulted to `1` when absent.

Also, I often want to look not necessarily the current position, but some position away. It would be good if `Enumerator#peek` takes an optional argument that represents the positional difference to be peeked. The argument can be understood to be defaulted to `0` when absent.

    enum = [0, 1, 2, 3, 4, 5, 6, 7, 8].to_enum
    enum.peek    # => 0
    enum.peek(0) # => 0
    enum.peek(1) # => 1
    enum.peek    # => 0
    enum.next    # => 0
    enum.next(1) # => 1
    enum.next(2) # => 2
    enum.peek    # => 4
    enum.peek(0) # => 4
    enum.peek(1) # => 5
    enum.peek    # => 4
    enum.next    # => 4
    enum.next(1) # => 5
    enum.next(2) # => 6
    peek         # => 8




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-11 18:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-9557.20140223091418@ruby-lang.org>
2014-02-23  9:14 ` [ruby-core:61030] [ruby-trunk - Feature #9557] [Open] Enumerator#next and Enumerator#peek with argument sawadatsuyoshi
2014-02-23 17:13 ` [ruby-core:61033] [ruby-trunk - Feature #9557] " matz
2014-02-23 18:41 ` [ruby-core:61034] " sawadatsuyoshi
2014-04-11 19:00 ` [ruby-core:61992] " transfire

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).