Skip to content

Commit 3f9ba7f

Browse files
authored
specify that Iterators.rest must be given a valid state (#58962)
~currently `Iterators.rest(1:2, 3)` creates an infinite loop. after this PR it would be an `ArgumentError`~ docs only now
1 parent 107e1ac commit 3f9ba7f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

base/iterators.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,19 @@ end
625625
"""
626626
rest(iter, state)
627627
628-
An iterator that yields the same elements as `iter`, but starting at the given `state`.
628+
An iterator that yields the same elements as `iter`, but starting at the given `state`, which
629+
must be a state obtainable via a sequence of one or more calls to `iterate(iter[, state])`
629630
630631
See also: [`Iterators.drop`](@ref), [`Iterators.peel`](@ref), [`Base.rest`](@ref).
631632
632633
# Examples
633634
```jldoctest
634-
julia> collect(Iterators.rest([1,2,3,4], 2))
635+
julia> iter = [1,2,3,4];
636+
637+
julia> val, state = iterate(iter)
638+
(1, 2)
639+
640+
julia> collect(Iterators.rest(iter, state))
635641
3-element Vector{Int64}:
636642
2
637643
3

0 commit comments

Comments
 (0)