You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix inconsistent behaviour for last(::Zip) with differing iterator size types (#59217)
This PR fixes two bugs relating to `last(::Zip)`, closing #58922.
First: there is inconsistent behaviour for `last(::Zip)` with differing
iterator size types (a mixture of known-size and not) are passed in the
`Zip`, causing a `MethodError`.
`last(::Zip)` works with finite zipped iterators of different lengths,
but fails when one of them is an infinite iterator. In the case where
there are a mixture of known-length (finite) and infinite iterators in
the `Zip`, we can know their length statically. (I call these `Zip`s
"finite-guarded," because the `Zip` is finite due to its finite
component.)
The desired behaviour is to match the behaviour of `last` with finite
iterators of different lengths.
Second: while standardising this behaviour, [a bug in `last(::Zip)` for
`OffsetArray`s](#58922 (comment))
is fixed. The issue was subtle and didn't error, but produced the wrong
answer (noticed by @adienes).
We also add an explicit `ArgumentError` when `last` is called on a `Zip`
whose size is unknown (good call by @Seelengrab). Previously this was a
`MethodError` for `lastindex`, used by the [previous implementation of
`last(::Zip)`](https://github.com/JuliaLang/julia/blob/80f7db8e51b2ba1dd21e913611c23a6d5b75ecab/base/iterators.jl#L476).
This PR does **not** give support to any [functionality involving
iterators of unknown
size](https://github.com/JuliaLang/julia/pull/59217/files#discussion_r2256315847).
This may be done in future.
0 commit comments