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
Hi,
I've turned the open ended issue #54454 into an actual PR.
Tangentially related to #10092 ?
This PR introduces the `nth(itr, n)` function to iterators to give a
`getindex` type of behaviour.
I've tried my best to optimize as much as possible by specializing on
different types of iterators.
In the spirit of iterators any OOB access returns `nothing`. (edit:
instead of throwing an error, i.e. `first(itr, n)` and `last(itr, n)`)
here is the comparison of running the testsuite (~22 different
iterators) using generic `nth` and specialized `nth`:
```julia
@Btime begin
for (itr, n, _) in $testset
_fallback_nth(itr, n)
end
end
117.750 μs (366 allocations: 17.88 KiB)
@Btime begin
for (itr, n, _) in $testset
nth(itr, n)
end
end
24.250 μs (341 allocations: 16.70 KiB)
```
---------
Co-authored-by: adienes <51664769+adienes@users.noreply.github.com>
Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
0 commit comments