flatMap<R extends Object> method

  1. @override
Resolvable<R> flatMap<R extends Object>(
  1. @noFutures Resolvable<R> noFutures(
    1. T value
    )
)
override

Chains another Resolvable-producing operation: the monadic bind for Resolvable. If this is in an Err state, the chain short-circuits with that Err. If noFutures throws, the throw is absorbed into an Err.

Equivalent to .then(...) followed by .flatten(), with the short-circuit and throw-absorption wired in.

Implementation

@override
@pragma('vm:prefer-inline')
Resolvable<R> flatMap<R extends Object>(
  @noFutures Resolvable<R> Function(T value) noFutures,
) {
  switch (value) {
    case Ok(value: final v):
      try {
        return noFutures(v);
      } on Err catch (err) {
        return Sync.err(err.transfErr<R>());
      } catch (error, stackTrace) {
        return Sync.err(Err<R>(error, stackTrace: stackTrace));
      }
    case final Err<T> err:
      return Sync.err(err.transfErr<R>());
  }
}