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

Make take_while short-circuit #2358

Merged
merged 1 commit into from
Nov 22, 2017
Merged

Make take_while short-circuit #2358

merged 1 commit into from
Nov 22, 2017

Conversation

Theodus
Copy link
Contributor

@Theodus Theodus commented Nov 20, 2017

This change makes Iter.take_while short-circuit the first time that
the predicate f returns false or raises an error. Previously, this
adapter would infinitely pull from an infinite iterator after the
predicate had already returned false.

resolves #2356

This change makes `Iter.take_while` short-circuit the first time that
the predicate `f` returns false or raises an error. Previously, this
adapter would infinitely pull from an infinite iterator after the
predicate had already returned false.

resolves #2356
@Theodus Theodus added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Nov 20, 2017
.take_while({(n) => n < 2 })
h.assert_eq[USize](0, infinite.next()?)
h.assert_eq[USize](1, infinite.next()?)
h.assert_false(infinite.has_next())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it makes sense to verify that a call to infinite.next() is also properly erroring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very good question and relates to a question that I was planning to ask in the next sync about what it means for an iterator to be "well behaved". I leave it out currently since some of the most common iterators will continue to give values after has_next returns false (such as Range).

@SeanTAllen SeanTAllen merged commit c028049 into ponylang:master Nov 22, 2017
ponylang-main added a commit that referenced this pull request Nov 22, 2017
@Theodus Theodus deleted the itertools branch November 22, 2017 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Iter.take_while doesn't support infinite iterators
3 participants