Skip to content

Commit 9cf0c9c

Browse files
authored
clarify doc for Iterators.reverse (#43522)
1 parent 20683ba commit 9cf0c9c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

base/iterators.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,20 @@ and_iteratoreltype(a, b) = EltypeUnknown()
7272
7373
Given an iterator `itr`, then `reverse(itr)` is an iterator over the
7474
same collection but in the reverse order.
75-
7675
This iterator is "lazy" in that it does not make a copy of the collection in
7776
order to reverse it; see [`Base.reverse`](@ref) for an eager implementation.
7877
78+
(By default, this returns
79+
an `Iterators.Reverse` object wrapping `itr`, which is iterable
80+
if the corresponding [`iterate`](@ref) methods are defined, but some `itr` types
81+
may implement more specialized `Iterators.reverse` behaviors.)
82+
7983
Not all iterator types `T` support reverse-order iteration. If `T`
8084
doesn't, then iterating over `Iterators.reverse(itr::T)` will throw a [`MethodError`](@ref)
81-
because of the missing [`iterate`](@ref) methods for `Iterators.Reverse{T}`.
85+
because of the missing `iterate` methods for `Iterators.Reverse{T}`.
8286
(To implement these methods, the original iterator
83-
`itr::T` can be obtained from `r = Iterators.reverse(itr)` by `r.itr`.)
87+
`itr::T` can be obtained from an `r::Iterators.Reverse{T}` object by `r.itr`;
88+
more generally, one can use `Iterators.reverse(r)`.)
8489
8590
# Examples
8691
```jldoctest

0 commit comments

Comments
 (0)