andThen<R> abstract method

Result<R, E> andThen<R>(
  1. Result<R, E> next(
    1. T value
    )
)

Chains another result-producing operation when this result is successful.

Use this when the next step can also fail.

Result<int, String> parseCount(String text) {
  final value = int.tryParse(text);
  return value == null ? const Err('invalid') : Ok(value);
}

Result<int, String> requirePositive(int value) {
  return value > 0 ? Ok(value) : const Err('must be positive');
}

final parsed = parseCount('2').andThen(requirePositive);
final failed = parseCount('-1').andThen(requirePositive);

Implementation

Result<R, E> andThen<R>(Result<R, E> Function(T value) next);