spebbe / dartz

Functional programming in Dart
MIT License
749 stars 60 forks source link

biFlatMap for Either #104

Closed otto-dev closed 2 years ago

otto-dev commented 2 years ago

Proposed function signature:

  Either<LL, RR> biFlatMap<LL, RR>(Either<LL, RR> ifLeft(L l), Either<LL, RR> ifRight(R r)) =>

Example use case:

For example, remoteLogin(String user, String password) may return either a network error (Left) or a response (Right). But if there is a response, the login may still be invalid. So I want to biFlatMap the Either. In biFlatMap, if there is a network error, I want to normalize it. If there is a response, I want it to become a Left if the login is invalid, otherwise keep it a Right.

otto-dev commented 2 years ago

It's just fold lol