NAME

Sidef::Types::Null::Null - The Null type in Sidef

DESCRIPTION

This class implements the Null type in Sidef, representing the absence of a value or an undefined state. Null is a singleton object that serves as Sidef's representation of "nothing" or "no value". It is commonly used as a default return value for operations that don't produce meaningful results, or to indicate the absence of data.

The Null object evaluates to false in boolean contexts and can be used for nil-checking patterns common in many programming scenarios.

SYNOPSIS

# Null is automatically returned by some operations
var result = [1,2,3].first { _ > 10 }  # returns Null if not found

# Explicit Null creation
var obj = Null()
var nothing = Null.new

# Boolean context - Null is falsy
if (Null) {
    say "This won't execute"
}

# Checking for Null
if (result == Null) {
    say "No result found"
}

# Using Null in conditionals
var value = some_function() \\ "default"  # Use default if Null

# Converting Null to string
say Null.to_s  # prints "null"

INHERITS

Inherits methods from:

* Sidef::Object::Object

METHODS

new

Null.new
self.new

Returns the singleton Null object. Since Null is a singleton, all calls to new return the same Null instance.

Example:

var n1 = Null.new
var n2 = Null.new
say (n1 == n2)  # true - same object

Aliases: call

to_s

Null.to_s
self.to_s

Returns the string representation of the Null object, which is the lowercase string "null".

Example:

say Null.to_s        # prints: null
say "Value: #{Null}" # prints: Value: null

Returns: A String object containing "null"

Aliases: dump, to_str

BOOLEAN CONTEXT

The Null object evaluates to false in boolean contexts:

if (Null) {
    # This block never executes
}

say (Null ? "true" : "false")  # prints: false
say (!Null)                     # prints: true

EQUALITY AND COMPARISON

Null can be compared with other values:

say (Null == Null)      # true
say (Null == nil)       # true (nil is an alias)
say (Null == false)     # false
say (Null == 0)         # false
say (Null == "")        # false

COMMON USES

  • Default return value for functions that find no result

    var item = array.first { condition }  # returns Null if not found
  • Optional parameters and missing values

    func process(value = Null) {
        if (value != Null) {
            # Process the value
        }
    }
  • Nil-coalescing operations

    var result = might_be_null() \\ default_value
  • Database NULL representations

  • Absence of object references

SEE ALSO

AUTHOR

Daniel Șuteu, <trizen@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2013-2025 Daniel Șuteu

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.2 or, at your option, any later version of Perl 5 you may have available.