andThen<U> method
Calls op
if the result is Ok
,
otherwise returns the Err
value of this
.
This function can be used for control flow based on Result
values.
Examples
Basic usage:
Result<int, String> parseToInt(String value) {
try {
return Ok(int.parse(value));
} catch (_) {
return Err(value);
}
}
Result<String, String> x = Ok('4');
Result<int, String> y = x.andThen(parseToInt);
expect(y, Ok(4));
Implementation
@override
Result<U, E> andThen<U>(Result<U, E> Function(T value) okMap) {
return okMap(v);
}