1

我有一段看起来像这样的代码:

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(),
    );
  },
);

基本上,我想调用第一个函数,它返回一个失败或一个单元(成功值无关紧要)。

然后,如果第一个函数成功,我想调用另一个函数,它也返回 Future 或 Unit。

我该怎么做才能避免这种丑陋的嵌套调用foldinside another fold

我正在使用包dartz,这真的很酷,但缺乏文档。

4

0 回答 0