Open morgen-peschke opened 1 month ago
Perhaps, mouse can help out with that F[Option[...]]
case:
import mouse.foption.*
def lookupSomething(id: ID): F[Option[Something]] = ???
val res: F[Something] =
lookupSomething(id).getOrElseF {
log(s"nothing found for $id") >>
F.raiseError(new RuntimeException("not found"))
}
A common pattern shows up in our code that doesn't seem to have an elegant solution: we'd like to log before raising an error (usually from an
Option
).Currently, there are a couple ways to accomplish this for
Option
values (in rough order of increasing subjective elegance):The situation for
Either
(orValidated
) is much better, but still not great:I propose adding variants of
ApplicativeError#from*
toMonadError
and their equivalent variants of theliftTo
helpers inOptionSyntax
EitherSyntax
andValidatedSyntax
, which would allow writing the above as: