Template match

Calls an appropriate handler depending on if the optional has a value or not

template match(handlers...) ;

If either handler returns void, the return type of match is void.

Contained Functions

NameDescription
match

Parameters

NameDescription
opt The optional to call match on
handlers 2 predicates, one that takes the underlying optional type and another that names nothing

Example

auto a = some(3);
auto b = no!int;

auto ra = a.match!(
    (int a) => "yes",
    () => "no",
);

auto rb = b.match!(
    (a) => "yes",
    () => "no",
);

assert(ra == "yes");
assert(rb == "no");