Skip to content

Commit c308b91

Browse files
timholytkelman
authored andcommitted
Expand docs on enumerate's relationship with indexing
(cherry picked from commit 2311507) ref #17978
1 parent bc19ea4 commit c308b91

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

base/iterator.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ end
2121
"""
2222
enumerate(iter)
2323
24-
An iterator that yields `(i, x)` where `i` is an index starting at 1, and
25-
`x` is the `i`th value from the given iterator. It's useful when you need
26-
not only the values `x` over which you are iterating, but also the index `i`
27-
of the iterations.
24+
An iterator that yields `(i, x)` where `i` is a counter starting at 1,
25+
and `x` is the `i`th value from the given iterator. It's useful when
26+
you need not only the values `x` over which you are iterating, but
27+
also the number of iterations so far. Note that `i` may not be valid
28+
for indexing `iter`; it's also possible that `x != iter[i]`, if `iter`
29+
has indices that do not start at 1.
2830
2931
```jldoctest
3032
julia> a = ["a", "b", "c"];

doc/stdlib/collections.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ type.
8181

8282
.. Docstring generated from Julia source
8383
84-
An iterator that yields ``(i, x)`` where ``i`` is an index starting at 1, and ``x`` is the ``i``\ th value from the given iterator. It's useful when you need not only the values ``x`` over which you are iterating, but also the index ``i`` of the iterations.
84+
An iterator that yields ``(i, x)`` where ``i`` is a counter starting at 1, and ``x`` is the ``i``\ th value from the given iterator. It's useful when you need not only the values ``x`` over which you are iterating, but also the number of iterations so far. Note that ``i`` may not be valid for indexing ``iter``\ ; it's also possible that ``x != iter[i]``\ , if ``iter`` has indices that do not start at 1.
8585

8686
.. doctest::
8787

0 commit comments

Comments
 (0)