The actual map function.
A new Expected object containing the result.
1 { 2 assert(ok(42).map!(a => a/2).value == 21); 3 assert(ok().map!(() => 42).value == 42); 4 assert(err!int("foo").map!(a => 42).error == "foo"); 5 assert(err("foo").map!(() => 42).error == "foo"); 6 } 7 8 // remap hook 9 { 10 static struct Hook {} 11 auto res = ok(42).map!(a => a/2, Hook); 12 assert(res == 21); 13 static assert(is(typeof(res) == Expected!(int, string, Hook))); 14 }
Applies a function to the expected value in an Expected object.
If no expected value is present, the original error value is passed through unchanged, and the function is not called.