thenFold<B> method
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));
}