Struct Expect

The expect type can be used to return values and error codes from functions

struct Expect(T, E)
if (!is(E == void));

The "expected" value is the success value and the unexpected (which is also typed as Unexpected) is the failure value.

The default value is always the init value of the expected case

You may also call ddash.utils.match on an Expect value.


this Constructor takes a Expected and creates a success result. Or takes an E and creates an unexpected result


expected Create an Expect with an expected value
isExpected Returns true if the value is expected
opEquals compares a value or an unexpected value. To compare with an unepexted value you must used either Unexpected!E as the rhs or it's type contructor.
toString Calls!string on T or E
unexpected Create an Expect with an unexpected value


Expect!int toInt(string str) {
    alias Result = typeof(return);
    import std.conv: to;
    try {
        return Result.expected(!int);
    } catch (Exception ex) {
        return Result.unexpected(ex.msg);

assert(toInt("33") == 33);
assert(toInt("!33") == anyUnexpected);