Constructing Maybe from value. If pointer is null methods: isNothing returns true and get throws Error.
Alias to stored type
Unwrap value from Maybe. If stored value is null, Error is thrown.
Unwrap value from Maybe. If stored value is null, 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 class A {} 2 3 auto a = new A(); 4 auto ma = Maybe!A(a); 5 auto mb = Maybe!A(null); 6 7 assert(!ma.isNothing); 8 assert(mb.isNothing); 9 10 assert(ma.get == a); 11 assertThrown!Error(mb.get); 12 13 bool ncase = false, jcase = false; 14 ma.map(() {ncase = true;}, (v) {jcase = true;}); 15 assert(jcase && !ncase); 16 17 ncase = jcase = false; 18 mb.map(() {ncase = true;}, (v) {jcase = true;}); 19 assert(!jcase && ncase);
Struct-wrapper to handle result of computations, that can fail.