thenFold<B> method

Future<B> thenFold<B>(
  1. B ok(
    1. O ok
    ),
  2. B err(
    1. E err
    )
)

used to fold a Result from a Future.

It is the same as .then() except it folds the returned value.

Example:

Future<Result<String, Error>> getData() async {
  await Future.delayed(500.milliseconds);
  return Ok('hi');
}
getData().foldAsync(
  (ok) => print(ok),
  (err) => print(err),
);

Implementation

Future<B> thenFold<B>(B Function(O ok) ok, B Function(E err) err) async {
  final result = await this;
  return result.fold((value) => ok(value), (error) => err(error));
}