Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
907 B

package wow.doge.mygame.utils
import cats.data.Reader
import cats.data.ReaderT
import monix.bio.UIO
object ReaderDemo {
type IoReaderT[S, E, A] = ReaderT[UIO, S, Either[E, A]]
val IoReaderT = ReaderT
val t =
ReaderT[UIO, String, Either[Error, Unit]](s => UIO.unit.attempt)
.run("s")
.rethrow
val r: IoReaderT[String, Error, Unit] = IoReaderT(s => UIO.unit.attempt)
val t2 = r.run("s").rethrow
// Kleisli[IO, String, Unit](s => IO.unit)
case class Environment(str: String, num: Int)
def fun1: Reader[String, UIO[Unit]] = Reader(str => UIO(println(str)))
def fun2: Reader[Int, UIO[Unit]] = Reader(num => UIO(println(num)))
def total: Reader[Environment, UIO[Unit]] =
for {
x <- fun1.local[Environment](_.str)
y <- fun2.local[Environment](_.num)
} yield UIO.parSequence(List(x, y)).void
val io: UIO[Unit] = total.run(Environment("hello", 50))
}