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 isnothing #29679

Merged
merged 6 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
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"))

"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be added to the documentation so it shows up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - I added it next to Nothing.

isnothing(x)

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


"""
something(x, y...)

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)