Issue #6166 has been updated by trans (Thomas Sawyer).


It should have no effect on `lz` either way. It does not act in place.

  lz = (1..100).lazy
  lz.pinch(0,2)  #=> [1,2]
  lz.pinch(0,2)  #=> [1,2]

Marc-Andre's suggestion of #slice is better name. I forgot about that method, but it is exactly what I intended --so long as #slice is not going to be lazy itself.

Sequences are indexable in that #to_a can be called, the methods follows the same procedure but stops when the end sentinel is reached.

Hmmm... I suppose another option would be to let #to_a take arguments.

  lz = (1..100).lazy
  lz.to_a(0,2)  #=> [1,2]

But that may not be good idea b/c #to_a does not take arguments in other classes.

----------------------------------------
Feature #6166: Enumerator::Lazy#pinch
https://bugs.ruby-lang.org/issues/6166#change-25573

Author: trans (Thomas Sawyer)
Status: Rejected
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 


In previous issue #6158 it has been determined that Enumerator::Lazy#take should be lazy. But an eager form of #take would still be useful.

To this end I'll suggest `Enumerator::Lazy#pinch`. Examples of usage:

    e.lazy.pinch 1

    e.lazy.pinch 1..2

    e.lazy.pinch 1,2

It is basically equivalent to calling `to_a[index]`, but has the advantage of being a single invocation instead of two, and reads better.

The #pinch method would be strictly a Lazy method and have no counterpart in Enumerable.



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