Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add precision about stateful iterators to isempty #43900

Merged
merged 3 commits into from
Mar 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add precision about stateful iterators to isempty
The manual now mentions that stateful iterators should implement `isdone`,
so it appears `isempty` is not supposed to consume elements.
This matters a lot for callers as if you can't rely on this you can't do
`isempty(c) && return; for x in c` but instead have to call `iterate(c)` manually.
  • Loading branch information
nalimilan committed Jan 23, 2022
commit 0f5eba6205228ef416887202f888de15ac96c8c1
3 changes: 3 additions & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,9 @@ inferencebarrier(@nospecialize(x)) = Ref{Any}(x)[]

Determine whether a collection is empty (has no elements).

This operation is guaranteed not to consume elements even for stateful
iterators (which should define [`Base.isdone`](@ref) to that end).
nalimilan marked this conversation as resolved.
Show resolved Hide resolved

# Examples
```jldoctest
julia> isempty([])
Expand Down