Optional.visit

Interface to retrieve stored value. It is intentionally designed in a way that forces you to handle "undefined" state to avoid issues akin to "null pointer".

This will become more convenient with D2 when lambda type inference will happen, as well as shorter notation:

value.visit(
    ()  => { },
    (x) => { }
);
struct Optional(T)
void
visit
(
scope void delegate
()
cb_undefined
,
scope void delegate
(
ref T
)
cb_defined
)

Parameters

cb_undefined void delegate
()

action to take if value is not defined

cb_defined void delegate
(
ref T
)

ditto for defined. May modify internal value via reference

Meta