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 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions base/some.jl
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
Sponsor 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
6 changes: 6 additions & 0 deletions test/some.jl
Expand Up @@ -94,3 +94,9 @@ b = [ "replacement", "replacement", nothing, missing ]
using Base: notnothing
@test notnothing(1) === 1
@test_throws ArgumentError notnothing(nothing)

# isnothing()

using Base: isnothing
Copy link
Member

Choose a reason for hiding this comment

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

I'd add this to base/exports.jl next to ismissing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ararslan check.

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