Skip to content

Commit

Permalink
Make iterate(::Number) more digestible by abstract_iteration
Browse files Browse the repository at this point in the history
Letting the presence of a second argument alone decide whether iteration
is done lets `abstract_iteration` determine that splatting a `Number`
yields exactly one `Number`.
  • Loading branch information
martinholters committed Jun 26, 2018
1 parent 78b9e89 commit e086018
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/number.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ julia> widemul(Float32(3.), 4.)
"""
widemul(x::Number, y::Number) = widen(x)*widen(y)

iterate(x::Number, done = false) = done ? nothing : (x, true)
iterate(x::Number) = (x, nothing)
iterate(x::Number, ::Any) = nothing
isempty(x::Number) = false
in(x::Number, y::Number) = x == y

Expand Down
5 changes: 5 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6235,3 +6235,8 @@ function f27597(y)
end
@test f27597([1]) == [1]
@test f27597([]) == 1:0

# issue #22291
wrap22291(ind) = (ind...,)
@test @inferred(wrap22291(1)) == (1,)
@test @inferred(wrap22291((1, 2))) == (1, 2)

0 comments on commit e086018

Please sign in to comment.