Optional

types/optional.ql

An entity that may either hold a value or be empty. The value being held may be anything.

Constructor Overview

Constructor Description
Optional(_value, _hasValue)

Creates a new optional with the given value and if it has a value. It is strongly recommended to just use fromValue() or fromEmpty()

Function Overview

Function Description
static fun fromValue(value) Creates an optional from a value.
static fun fromEmpty() Creates an empty optional.
fun hasValue() Checks if the optional has a value.
fun getValue() Gets the value of the optional. This will stop the program if the optional is empty, so check first via hasValue().
fun clearValue() Clears the value of the optional.
fun setValue(value) Sets the value of the optional.
fun toString()

Field Overview

Field Description
any _value

The value of the optional.

boolean _hasValue

If the optional has a value.

Constructors

Optional(_value, _hasValue) link

Creates a new optional with the given value and if it has a value. It is strongly recommended to just use fromValue() or fromEmpty()

Functions

static fun fromValue(value) link

Creates an optional from a value.

Params
value

The value to create the optional from. This may be any type

Returns Optional

The optional created from the value

static fun fromEmpty() link

Creates an empty optional.

Returns Optional

An empty optional

fun hasValue() link

Checks if the optional has a value.

Returns boolean

If the optional has a value

fun getValue() link

Gets the value of the optional. This will stop the program if the optional is empty, so check first via hasValue().

Returns

The value of the optional, any type

fun clearValue() link

Clears the value of the optional.

fun setValue(value) link

Sets the value of the optional.

Params
value

The value to set