Julia: Add isnothing() function?

Created on 16 Oct 2018  Â·  1Comment  Â·  Source: JuliaLang/julia

This came up on slack in the #data channel: it would be nice to have a function to check if something is Nothing, since (apparently) x == nothing has a performance hit, and it's easy to forget to use x === nothing. Related: #28700

More importantly from my perspective, it has a nice symmetry with ismissing() and isnan(). I'm always expecting this to be a thing.

I did some searching in the repo and in discourse, where I found this comment

To simplify checking for nothingness, I wonder whether it’d be helpful to have isnothing (analogous to ismissing), but it’s also true that x isa Nothing isn’t much longer.

The only thing in the repo when I search for "isnothing" is a comment in #414 that uses it in some code (not sure if that was an assumption or if it used to be a thing and isn't anymore).

Working on a simple PR that would add this if there's interest. Basically just

isnothing(x::Any) = x === nothing ? true : false

(plus docs and tests of course 😆)

Most helpful comment

Resolved by #29679

>All comments

Resolved by #29679

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tkoolen picture tkoolen  Â·  3Comments

manor picture manor  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments

Keno picture Keno  Â·  3Comments

musm picture musm  Â·  3Comments