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