Trial

A interface to represent whether a value or an exception.

Members

Functions

get
T get()

Return value if this is the Success!T instance, otherwise throw Exception in the Failure!T instance.

getOrLeft
Either!(Exception, T) getOrLeft()

Return Right!(Exception, T) value if this is the Success!T instance, otherwise Left!(Exception, T) value.

Properties

isFailure
bool isFailure [@property getter]

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

isSuccess
bool isSuccess [@property getter]

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

Static functions

trying
Trial!T trying(T function() expr)

A factory method to create Trial(T) instance.

Examples

1 auto trial = Trial!int.trying({ return 9; });
2 if (trial.isSuccess)
3 {
4    writeln(trial.get());
5 }

Output:

9

Meta