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

3 years ago
  1. package wow.doge.mygame.utils
  2. import cats.data.Reader
  3. import cats.data.ReaderT
  4. import monix.bio.UIO
  5. object ReaderDemo {
  6. type IoReaderT[S, E, A] = ReaderT[UIO, S, Either[E, A]]
  7. val IoReaderT = ReaderT
  8. val t =
  9. ReaderT[UIO, String, Either[Error, Unit]](s => UIO.unit.attempt)
  10. .run("s")
  11. .rethrow
  12. val r: IoReaderT[String, Error, Unit] = IoReaderT(s => UIO.unit.attempt)
  13. val t2 = r.run("s").rethrow
  14. // Kleisli[IO, String, Unit](s => IO.unit)
  15. case class Environment(str: String, num: Int)
  16. def fun1: Reader[String, UIO[Unit]] = Reader(str => UIO(println(str)))
  17. def fun2: Reader[Int, UIO[Unit]] = Reader(num => UIO(println(num)))
  18. def total: Reader[Environment, UIO[Unit]] =
  19. for {
  20. x <- fun1.local[Environment](_.str)
  21. y <- fun2.local[Environment](_.num)
  22. } yield UIO.parSequence(List(x, y)).void
  23. val io: UIO[Unit] = total.run(Environment("hello", 50))
  24. }