Created
July 14, 2017 07:28
-
-
Save rjsvaljean/a285daf5ec24f6795a7ffa1a60722447 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| case class ValidatedT[F[_], +E, +A](run: F[Validated[E, A]]) | |
| import cats.Monad | |
| import cats.syntax.flatMap._ | |
| object ValidatedT { | |
| implicit def monad[F[_]: Monad, E]: Monad[({type l[a] = ValidatedT[F, E, a]})#l] = new Monad[({type l[a] = ValidatedT[F, E, a]})#l] { | |
| def pure[A](x: A) = ValidatedT(Monad[F].pure(Validated.valid(x))) | |
| def flatMap[A, B](fa: ValidatedT[F, E, A])(f: (A) => ValidatedT[F, E, B]) = | |
| ValidatedT(fa.run.flatMap(_.fold(e => Monad[F].pure(Validated.invalid[E, B](e)), i => f(i).run))) | |
| def tailRecM[A, B](a: A)(f: (A) => ValidatedT[F, E, Either[A, B]]) = ??? | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment