-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 Iterators.cycle(iter, n)
#47354
Add Iterators.cycle(iter, n)
#47354
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Maybe should have an entry in NEWS.md
?
Co-authored-by: Max Horn <max@quendi.de>
Thanks! Running my benchmark above on 1.11, the advantage of |
I think the overall new API is good; optimizations are of course welcome but better to have this in than to wait for the perfect version, I'd say |
|
Maybe this comment was for #53291? I note that |
I just mean if there's gonna be an |
This PR hoped not to get tangled up in renaming things... I thought This PR documents that
Besides arrays, the eager function has a method for Char: One downside of calling this method |
SGTM |
At present
Iterators.repeated(iter, n)
is the lazy cousin offill(iter, n)
, but there is no iterator forrepeat(iter, n)
. This PR proposes thatIterators.cycle(iter, n)
should fill that role.This relates to the one-argument form in the same way as
Iterators.repeated
. That is,cycle(iter)
meanscycle(iter, Inf)
in the same way thatrepeated(iter)
meansrepeated(iter, Inf)
... or would be if Inf were an integer.The implementation uses
flatten(repeated(xs, n))
. It could instead usetake(cycle(xs), n * length(xs))
but that only works when the contents has known length.take(cycle...)
tends to be faster, perhaps it should be used when possible? Some timing below. But perhaps this detail is a secondary question.