Maybe

A interface to represent an optional value.

Members

Functions

fromJust
T fromJust()

Return value if this is the Just!T instance, otherwise throw Exception.

Properties

isJust
bool isJust [@property getter]

Return true if this is the Just!T instance, otherwise false.

isNothing
bool isNothing [@property getter]

Return true if this is the Nothing!T instance, otherwise false.

Static functions

just
Maybe!T just(T value)

A factory method to create Just(T) instance.

nothing
Maybe!T nothing()

A factory method to create Nothing(T) instance.

Examples

1 auto maybe = Maybe!int.just(42);
2 if (maybe.isJust)
3 {
4    writeln(maybe.fromJust());
5 }

Output:

42

Meta