Created
March 17, 2021 16:41
-
-
Save ChristopherDavenport/28944d36f7456d2aaf64bf83902614f3 to your computer and use it in GitHub Desktop.
Generic Monad Transformer Lift Toolkit
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
| trait LiftF[M[_[_], _]]{ | |
| def liftF[F[_], A](fa: F[A])(implicit ev: cats.Monad[F]): M[F, A] | |
| } | |
| object LiftF { | |
| implicit class LiftOps[F[_], A](private val fa: F[A]){ | |
| def liftF[M[_[_], _]](implicit ev1: LiftF[M], ev2: Monad[F]): M[F, A] = | |
| ev1.liftF(fa) | |
| } | |
| implicit val resourceHoist: LiftF[Resource] = new LiftF[Resource] { | |
| def liftF[F[_], A](fa: F[A])(implicit ev: Monad[F]): Resource[F,A] = | |
| Resource.liftF(fa) | |
| } | |
| def lifted[F[_]: Sync] = for { | |
| _ <- Sync[F].delay(println("Foo")).liftF[Resource] | |
| } yield () | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment