isnull
isnull(x)
Is the Nullable object x null, i.e. missing a value?
Examples
The isnull(x) function in Julia is used to check whether a Nullable object x is null, meaning it is missing a value. Here are some examples of how to use the isnull function:
-
Check if a Nullable object is null:
julia> y = Nullable{Int}(5); julia> isnull(y) falseIn this example,
yis aNullableobject initialized with a value of 5. Theisnullfunction returnsfalsebecauseyis not null. -
Handle cases when a Nullable object is null:
julia> z = Nullable{String}(); julia> isnull(z) trueHere,
zis aNullableobject of typeStringwithout any assigned value. Theisnullfunction returnstruebecausezis null. - Determine nullness of an array of Nullable objects:
julia> arr = [Nullable(1), Nullable{Float64}(), Nullable("Julia")]; julia> isnull.(arr) 3-element BitArray{1}: false true falseThis example demonstrates the use of broadcasting
isnullover an array ofNullableobjects. Theisnull.(arr)syntax applies theisnullfunction to each element of the arrayarr, resulting in a boolean array indicating nullness.
Common mistake example:
julia> x = Nullable{Int}(5);
julia> isnull(x, 3)
ERROR: MethodError: no method matching isnull(::Nullable{Int64}, ::Int64)
In this example, the isnull function is mistakenly called with two arguments. The isnull function only takes one argument, which is the Nullable object to be checked for nullness. Avoid passing additional arguments to isnull.
See Also
BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.