Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Iterator#auto_rewind? and auto_rewind= #3796

Conversation

makenowjust
Copy link
Contributor

If Iterator#auto_rewind? returns true, the iterator is rewinded after Iterator#each automatically. Otherwise it returns false, the iterator is not rewinded.

Iterator#auto_rewind? default value is true, it is just breaking change.

This feature motivation is to be able to apply more Enumerable algorithm to Iterator. In current implementation, Iterator#each works only first time.

@asterite
Copy link
Member

I'm not sure about this. I prefer an explicit rewind, otherwise it can be very confusing.

@makenowjust
Copy link
Contributor Author

@asterite But we cannot use Iterator as Enumerable without attentions now...

@makenowjust makenowjust force-pushed the feature/iterator/auto-rewind branch 2 times, most recently from 9740817 to 894b2d7 Compare December 30, 2016 01:26
If Iterator#auto_rewind? returns true, the iterator is rewinded after Iterator#each
automatically. Otherwise it returns false, the iterator is not rewinded.

Iterator#auto_rewind? default value is true, it is just breaking change.

This feature motivation is to be able to apply Enumerable algorithm to
Iterator. In current implementation, `Iterator#each` works only first
time.
@asterite
Copy link
Member

@makenowjust Yes, because Iterator is not an Enumerable. You can use cycle to cycle.

@asterite asterite closed this Jan 11, 2017
@asterite
Copy link
Member

(well, it's an Enumerable, but its elements are consumed, and once you do that, you need to invoke rewind. Auto-rewind is not good because it means it's almost implicit behaviour)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants