I have a piece of code that look like this:
final Either<Failure, Unit> resA = await deleteA();
resA.fold(
(failure) => handleFailure(),
(success) async {
final Either<Failure, Unit> resB = await deleteB();
resB.fold(
(failure) => handleFailure(),
(success) => handleSuccess(),
);
},
);
Basically, I want to call a first function, that returns either a Failure or a Unit (the success value doesn't matter).
Then, if the first function succeeded, I want to call another function, that also return either a Future or a Unit.
How could I do to avoid this ugly nested call of fold
inside another fold
?
I'm working with the package dartz, which is really cool, but lacks of documentation.