From: "shugo (Shugo Maeda)" Date: 2012-03-23T18:49:27+09:00 Subject: [ruby-core:43575] [ruby-trunk - Feature #6166] Enumerator::Lazy#pinch Issue #6166 has been updated by shugo (Shugo Maeda). Hello, trans (Thomas Sawyer) wrote: > 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. Enumerator::Lazy#pinch provides a random access feature for Enumerator::Lazy, but Enumerator::Lazy is not random accessible in general, so I prefer explicit conversion like to_a[1, 2] to pinch. How about others? ---------------------------------------- Feature #6166: Enumerator::Lazy#pinch https://bugs.ruby-lang.org/issues/6166#change-25069 Author: trans (Thomas Sawyer) Status: Open Priority: Normal Assignee: 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/