-
-
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
In v2, Iterators.peel could return nothing
when iterator is empty
#39569
Comments
Care to make a PR? Looks like it should be non-breaking, since an attempt later to index or splat that |
Sure. If for some reason you do iterators.peel and pass the object along without looking at it, this would move the location of the exception quite a lot, but if that's okay I can do a PR. |
Fixes JuliaLang#39569. Old behaviour: ```jl try h, t = Iterators.peel(itr) # do something with h and t catch e if e isa BoundsError # itr was probably empty else rethrow() end end ``` New behaviour: ```jl x = Iterators.peel(itr) if isnothing(x) # itr was empty end h, t = x ```
Fixes JuliaLang#39569. Old behaviour: ```jl try h, t = Iterators.peel(itr) # do something with h and t catch e if e isa BoundsError # itr was probably empty else rethrow() end end ``` New behaviour: ```jl x = Iterators.peel(itr) if isnothing(x) # itr was empty end h, t = x ```
Submitted a PR. It passes tests, but I think the change should probably be run against the wider ecosystem. |
Just did a code search on GitHub, and none of the 140 matches for Iterators.peel would be broken by this change. |
Iterators.peel
is a lazy version ofh, t... = collection
, which is a very common pattern in recursive code. I think it would be good if it were more ergonomic to use. Ifh, t... = collection
will still be eager in v2, I think the simplest improvement would be to haveIterators.peel
pass throughnothing
if the iterator is empty so that we don't need to do exception handling.Current behaviour:
New proposal:
The text was updated successfully, but these errors were encountered: