Skip to content

Commit

Permalink
Add isnothing (JuliaLang#29679)
Browse files Browse the repository at this point in the history
  • Loading branch information
kescobo authored and JeffBezanson committed Oct 18, 2018
1 parent f068f21 commit d401033
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ New language features
---------------------

* `CartesianIndices` can now be constructed from two `CartesianIndex`es `I` and `J` with `I:J` ([#29440]).
* `isnothing(::Any)` function can now be called to check whether something is a `Nothing`, returns a `Bool` ([#29679])

Language changes
----------------
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ export
missing,
skipmissing,
something,
isnothing,

# time
sleep,
Expand Down
9 changes: 9 additions & 0 deletions base/some.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ Throw an error if `x === nothing`, and return `x` if not.
notnothing(x::Any) = x
notnothing(::Nothing) = throw(ArgumentError("nothing passed to notnothing"))

"""
isnothing(x)
Return `true` if `x === nothing`, and return `false` if not.
"""
isnothing(::Any) = false
isnothing(::Nothing) = true


"""
something(x, y...)
Expand Down
1 change: 1 addition & 0 deletions doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Core.NamedTuple
Base.Val
Core.Vararg
Core.Nothing
Base.isnothing
Base.Some
Base.something
Base.Enums.@enum
Expand Down
4 changes: 4 additions & 0 deletions test/some.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ b = [ "replacement", "replacement", nothing, missing ]
using Base: notnothing
@test notnothing(1) === 1
@test_throws ArgumentError notnothing(nothing)

# isnothing()
@test !isnothing(1)
@test isnothing(nothing)

0 comments on commit d401033

Please sign in to comment.