Last active
July 10, 2018 13:17
-
-
Save loicdescotte/a3cab52dcf3e62483105bafb3e3d910e to your computer and use it in GitHub Desktop.
Tagless final with MonadError
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats._ | |
import cats.implicits._ | |
def loadResult[F[_]](implicit F: MonadError[F, Throwable]): F[String] = { | |
val resultEitherF: F[Either[Throwable, String]] = ??? | |
val resultF: F[String] = resultEitherF.flatMap(F.fromEither) | |
resultF.recoverWith{ | |
case error => F.pure(error.getMessage) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Throwing[F[_]] = cats.MonadError[F, Throwable] | |
def loadResult[F[_] : Throwing]: F[String] = { | |
val resultEitherF: F[Either[Throwable, String]] = ??? | |
val resultF: F[String] = resultEitherF.flatMap(MonadError[F, Throwable].fromEither) | |
resultF.recoverWith{ | |
case error => MonadError[F, Throwable].pure(error.getMessage) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment