Optional

A simple wrapper around a value to make it optionally present.

Members

Functions

asNullable
Nullable!T asNullable()

Converts this optional to a Phobos-style Nullable.

opCast
bool opCast()

Provides a mechanism to allow usage in boolean expressions.

orElse
T orElse(T defaultValue)

Gets the value of this optional if it exists, otherwise uses a given default value.

orElseThrow
T orElseThrow(string msg)

Gets the value of this optional if it exists, or throws an exception.

orElseThrow
T orElseThrow(Exception delegate() exceptionSupplier)

Gets the value of this optional if it exists, or throws an exception as produced by the given delegate.

Static functions

empty
Optional!T empty()

Constructs an optional that's empty.

of
Optional!T of(T value)

Constructs an optional value using a given value.

of
Optional!T of(Nullable!T nullableValue)

Constructs an optional value using a Phobos nullable.

Variables

isNull
bool isNull;

Whether this optional is empty.

value
T value;

The internal value of this optional.