Skip to content

Commit

Permalink
clarify doc for Iterators.reverse (JuliaLang#43522)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored May 10, 2022
1 parent 20683ba commit 9cf0c9c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,20 @@ and_iteratoreltype(a, b) = EltypeUnknown()
Given an iterator `itr`, then `reverse(itr)` is an iterator over the
same collection but in the reverse order.
This iterator is "lazy" in that it does not make a copy of the collection in
order to reverse it; see [`Base.reverse`](@ref) for an eager implementation.
(By default, this returns
an `Iterators.Reverse` object wrapping `itr`, which is iterable
if the corresponding [`iterate`](@ref) methods are defined, but some `itr` types
may implement more specialized `Iterators.reverse` behaviors.)
Not all iterator types `T` support reverse-order iteration. If `T`
doesn't, then iterating over `Iterators.reverse(itr::T)` will throw a [`MethodError`](@ref)
because of the missing [`iterate`](@ref) methods for `Iterators.Reverse{T}`.
because of the missing `iterate` methods for `Iterators.Reverse{T}`.
(To implement these methods, the original iterator
`itr::T` can be obtained from `r = Iterators.reverse(itr)` by `r.itr`.)
`itr::T` can be obtained from an `r::Iterators.Reverse{T}` object by `r.itr`;
more generally, one can use `Iterators.reverse(r)`.)
# Examples
```jldoctest
Expand Down

0 comments on commit 9cf0c9c

Please sign in to comment.