replace Random.nth by Iterators.nth#61486
Merged
adienes merged 1 commit intoJuliaLang:masterfrom Apr 3, 2026
Merged
Conversation
oscardssmith
approved these changes
Apr 3, 2026
IanButterworth
added a commit
to IanButterworth/julia
that referenced
this pull request
Apr 7, 2026
Several functions and types introduced in Julia 1.13 were missing `!!! compat "Julia 1.13"` annotations in their docstrings, and some were absent from the API reference docs entirely. Add compat notes to: - `Iterators.nth` (base/iterators.jl) - `@__FUNCTION__` (base/runtime_internals.jl) - `Base.AbstractOneTo` (base/range.jl) - `Base.setindex(::ImmutableDict, ...)` (base/dict.jl) - `isassigned(::Tuple, ::Integer)` (base/tuple.jl; also adds docstring) - `Base.active_manifest` (base/initdefs.jl) - `macroexpand` `legacyscope` kwarg and `macroexpand!` (base/expr.jl) - `AbstractSpinLock` and `PaddedSpinLock` (base/locks-mt.jl) - Type annotation support in `gen_call_with_extracted_types` (stdlib/InteractiveUtils/src/macros.jl) Add missing `@docs` entries to the API reference for: - `Base.Iterators.nth` (doc/src/base/iterators.md) - `Base.AbstractOneTo` (doc/src/base/collections.md) - `Base.setindex(::ImmutableDict, ...)` (doc/src/base/collections.md) - `Base.isassigned(::Tuple, ::Integer)` (doc/src/base/arrays.md) - `Base.@acquire` (doc/src/base/parallel.md) - `Base.ScopedValues.AbstractScopedValue` (doc/src/base/scopedvalues.md) - `Base.ScopedValues.LazyScopedValue` (doc/src/base/scopedvalues.md) Also declare `Base.setindex` as public in base/public.jl, which was inadvertently omitted from the original PR (JuliaLang#59880), and fix `nth` → `Iterators.nth` in HISTORY.md following the rename in JuliaLang#61486. Co-Authored-By: Claude <claude@users.noreply.github.com>
IanButterworth
added a commit
to IanButterworth/julia
that referenced
this pull request
Apr 7, 2026
Several functions and types introduced in Julia 1.13 were missing `!!! compat "Julia 1.13"` annotations in their docstrings, and some were absent from the API reference docs entirely. Add compat notes to: - `Iterators.nth` (base/iterators.jl) - `@__FUNCTION__` (base/runtime_internals.jl) - `Base.AbstractOneTo` (base/range.jl) - `Base.setindex(::ImmutableDict, ...)` (base/dict.jl) - `isassigned(::Tuple, ::Integer)` (base/tuple.jl; also adds docstring) - `Base.active_manifest` (base/initdefs.jl) - `macroexpand` `legacyscope` kwarg and `macroexpand!` (base/expr.jl) - `AbstractSpinLock` and `PaddedSpinLock` (base/locks-mt.jl) - Type annotation support in `gen_call_with_extracted_types` (stdlib/InteractiveUtils/src/macros.jl) Add missing `@docs` entries to the API reference for: - `Base.Iterators.nth` (doc/src/base/iterators.md) - `Base.AbstractOneTo` (doc/src/base/collections.md) - `Base.setindex(::ImmutableDict, ...)` (doc/src/base/collections.md) - `Base.isassigned(::Tuple, ::Integer)` (doc/src/base/arrays.md) - `Base.@acquire` (doc/src/base/parallel.md) - `Base.ScopedValues.AbstractScopedValue` (doc/src/base/scopedvalues.md) - `Base.ScopedValues.LazyScopedValue` (doc/src/base/scopedvalues.md) Also declare `Base.setindex` as public in base/public.jl, which was inadvertently omitted from the original PR (JuliaLang#59880), and fix `nth` → `Iterators.nth` in HISTORY.md following the rename in JuliaLang#61486. Co-Authored-By: Claude <claude@users.noreply.github.com>
IanButterworth
added a commit
to IanButterworth/julia
that referenced
this pull request
Apr 7, 2026
Several functions and types introduced in Julia 1.13 were missing `!!! compat "Julia 1.13"` annotations in their docstrings, and some were absent from the API reference docs entirely. Add compat notes to: - `Iterators.nth` (base/iterators.jl) - `@__FUNCTION__` (base/runtime_internals.jl) - `Base.AbstractOneTo` (base/range.jl) - `Base.setindex(::ImmutableDict, ...)` (base/dict.jl) - `isassigned(::Tuple, ::Integer)` (base/tuple.jl; also adds docstring) - `Base.active_manifest` (base/initdefs.jl) - `macroexpand` `legacyscope` kwarg and `macroexpand!` (base/expr.jl) - `AbstractSpinLock` and `PaddedSpinLock` (base/locks-mt.jl) - Type annotation support in `gen_call_with_extracted_types` (stdlib/InteractiveUtils/src/macros.jl) Add missing `@docs` entries to the API reference for: - `Base.Iterators.nth` (doc/src/base/iterators.md) - `Base.AbstractOneTo` (doc/src/base/collections.md) - `Base.setindex(::ImmutableDict, ...)` (doc/src/base/collections.md) - `Base.isassigned(::Tuple, ::Integer)` (doc/src/base/arrays.md) - `Base.@acquire` (doc/src/base/parallel.md) - `Base.ScopedValues.AbstractScopedValue` (doc/src/base/scopedvalues.md) - `Base.ScopedValues.LazyScopedValue` (doc/src/base/scopedvalues.md) Also declare `Base.setindex` as public in base/public.jl, which was inadvertently omitted from the original PR (JuliaLang#59880), and fix `nth` → `Iterators.nth` in HISTORY.md following the rename in JuliaLang#61486. Co-Authored-By: Claude <claude@users.noreply.github.com>
IanButterworth
added a commit
to IanButterworth/julia
that referenced
this pull request
Apr 7, 2026
Several functions and types introduced in Julia 1.13 were missing `!!! compat "Julia 1.13"` annotations in their docstrings, and some were absent from the API reference docs entirely. Add compat notes to: - `Iterators.nth` (base/iterators.jl) - `@__FUNCTION__` (base/runtime_internals.jl) - `Base.AbstractOneTo` (base/range.jl) - `Base.setindex(::ImmutableDict, ...)` (base/dict.jl) - `isassigned(::Tuple, ::Integer)` (base/tuple.jl; also adds docstring) - `Base.active_manifest` (base/initdefs.jl) - `macroexpand` `legacyscope` kwarg and `macroexpand!` (base/expr.jl) - `AbstractSpinLock` and `PaddedSpinLock` (base/locks-mt.jl) - Type annotation support in `gen_call_with_extracted_types` (stdlib/InteractiveUtils/src/macros.jl) Add missing `@docs` entries to the API reference for: - `Base.Iterators.nth` (doc/src/base/iterators.md) - `Base.AbstractOneTo` (doc/src/base/collections.md) - `Base.setindex(::ImmutableDict, ...)` (doc/src/base/collections.md) - `Base.isassigned(::Tuple, ::Integer)` (doc/src/base/arrays.md) - `Base.@acquire` (doc/src/base/parallel.md) - `Base.ScopedValues.AbstractScopedValue` (doc/src/base/scopedvalues.md) - `Base.ScopedValues.LazyScopedValue` (doc/src/base/scopedvalues.md) Also declare `Base.setindex` as public in base/public.jl, which was inadvertently omitted from the original PR (JuliaLang#59880), and fix `nth` → `Iterators.nth` in HISTORY.md following the rename in JuliaLang#61486. Co-Authored-By: Claude <claude@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Iterators.nthhas been added in #56580 for Julia 1.13. CurrentlyRandomhas its own (non-public)nthfunction, which is used forAbstractDictandAbstractSet. This PR replaces it byIterators.nth. Apart from removing redundant code, this also allows user-defined methods forIterators.nth(which is public) to be used inrand.Note that I call
Iterators.nthwith@inbounds. This doesn't make any difference for the default method (at least not forAbstractDictandAbstractSet), but it may do so for user-defined methods. I'm havingSmallBitSetfrom my package SmallCollections.jl in mind, wherenthis just some bit juggling, see matthias314/SmallCollections.jl#17. When filling a vector with random elements of aSmallBitSet, around 20% of the runtime would be spent on checking bounds. Of course, I can remove the@inboundsif you don't like it.I've also dropped the
::eltype(iter)return type indicator ofRandom.nth. I've testedSet{T}whereTis aUnionwith up to 6 elements, and alsoGenerator. In all cases,@code_typedcould predict the return type.