andThen<U> abstract method

Result<U, E> andThen<U>(
  1. Result<U, E> okMap(
    1. T value
    )
)

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

Result<U, E> andThen<U>(Result<U, E> Function(T value) okMap);