Is the Nullable object x null, i.e. missing a value?


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:

  1. Check if a Nullable object is null:

    julia> y = Nullable{Int}(5);
    julia> isnull(y)

    In this example, y is a Nullable object initialized with a value of 5. The isnull function returns false because y is not null.

  2. Handle cases when a Nullable object is null:

    julia> z = Nullable{String}();
    julia> isnull(z)

    Here, z is a Nullable object of type String without any assigned value. The isnull function returns true because z is null.

  3. Determine nullness of an array of Nullable objects:
    julia> arr = [Nullable(1), Nullable{Float64}(), Nullable("Julia")];
    julia> isnull.(arr)
    3-element BitArray{1}:

    This example demonstrates the use of broadcasting isnull over an array of Nullable objects. The isnull.(arr) syntax applies the isnull function to each element of the array arr, 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.

*Required Field

Checking you are not a robot: