Constructing Maybe from value. If Maybe is created with the constructor, it is considered non empty and isNothing returns false.
Alias to stored type
Unwrap value from Maybe. If the Maybe is empty, Error is thrown.
Unwrap value from Maybe. If the Maybe is empty, Error is thrown.
Returns true if stored value is null
If struct holds null, then nothingCase result is returned. If struct holds not null value, then $(justCase) result is returned. justCase is fed with unwrapped value.
If struct holds null, then nothingCase result is returned. If struct holds not null value, then $(justCase) result is returned. justCase is fed with unwrapped value.
Constructing empty Maybe. If Maybe is created with the method, it is considred empty and isNothing returns false.
Example
1 struct A {} 2 3 auto ma = Maybe!A(A()); 4 auto mb = Maybe!A.nothing; 5 6 assert(!ma.isNothing); 7 assert(mb.isNothing); 8 9 assert(ma.get == A()); 10 assertThrown!Error(mb.get); 11 12 bool ncase = false, jcase = false; 13 ma.map(() {ncase = true;}, (v) {jcase = true;}); 14 assert(jcase && !ncase); 15 16 ncase = jcase = false; 17 mb.map(() {ncase = true;}, (v) {jcase = true;}); 18 assert(!jcase && ncase);
Struct-wrapper to handle result of computations, that can fail.