result-flow
result-flow copied to clipboard
Support a method that returns either Err or Ok Result if original Result is Err?
returns the result of the given @{link Function}, wrapped in a new Err Result instance. Otherwise returns this
I'd like to return a Result instance that could be either Ok or Err. Is there any interest in adding this?
@davidxia I don't really think you should ever need to do that. If you have a function like that, then it would have some some unnecessary complexity inside. You should string your map() and mapErr() calls together to handle the results like so:
Result<String, Exception> result = functionThatProducesResult();
result.map((value) -> {
// Do something with value
return value;
}).mapErr((err) -> {
// Do something with err
return err;
});