[ruby-core:63376] Re: Unexpected behaviour of cycle and zip

From: Jesús Gabriel y Galán <jgabrielygalan@...>
Date: 2014-06-27 20:53:54 UTC
List: ruby-core #63376
On Fri, Jun 27, 2014 at 6:41 PM, Marc-Andre Lafortune
<ruby-core-mailing-list@marc-andre.ca> wrote:
> Hi
>
>> Is it wrong to expect the enumerator to behave as a cycle starting from its current position for operations like zip and take?
>
> Your confusion is understandable, but this is not how the enumerators
> were designed. At the end of the doc for `next` you'll find:
>
>     Note that enumeration sequence by next does not affect other
> non-external enumeration methods, unless the underlying iteration
> methods itself has side-effect, e.g. IO#each_line
>
> I think this design choice is in part because using `next` is much
> slower then `each`.
>
> Hope this helps.

Thanks a lot for your answer. Somehow I overlooked that line, I guess
I was looking at zip and take, and not at next.

Jesus.

In This Thread

Prev Next