Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cats._, cats.data._, cats.implicits._
- import cats.free.Free
- import cats.arrow.FunctionK
- import monix.eval.Coeval
- object ParserForFreeMonad extends App {
- trait MyAlgebraF[A]
- final case class Append(cmd: String) extends MyAlgebraF[Int]
- final case class Upsert(cmd: String) extends MyAlgebraF[Unit]
- type MyAlgebra[A] = Free[MyAlgebraF, A]
- val nt = Lambda[FunctionK[MyAlgebraF, Coeval]] {
- case Append(cmd) => Coeval { println(cmd); 1 }
- case Upsert(cmd) => Coeval { println(cmd) }
- }
- val prog = for {
- a <- Free.liftF(Append("append"))
- u <- Free.liftF(Upsert("upsert"))
- } yield a
- println(prog.foldMap(nt).runTry)
- }
Add Comment
Please, Sign In to add comment