zio

Making sense of Scala FP Libraries

只谈情不闲聊 提交于 2020-05-09 18:47:04
问题 Just for the sake of quick clarity for someone who wants to start working with Scala FP library, on a journey to become better at pure FP. Would someone clarify the difference/relation between Cats and Cats-Effect, Cats-Effects IO? On top of that, where does Zio, and Monix stand with respect to it? Finally, what would be the relation to ScalaZ 7/8? So far based on what I have read, a good combination of the library to work with based on the documentation available and what they do would be

ZIO : How to compute only once?

百般思念 提交于 2019-12-24 00:44:01
问题 I am using ZIO: https://github.com/zio/zio in my build.sbt : "dev.zio" %% "zio" % "1.0.0-RC9" No matter what I tried, my results are always being computed each time I need them: val t = Task { println(s"Compute") 12 } val r = unsafeRun(for { tt1 <- t tt2 <- t } yield { tt1 + tt2 }) println(r) For this example, the log look like : Compute Compute 24 I tried with Promise : val p = for { p <- Promise.make[Nothing, Int] _ <- p.succeed { println(s"Compute - P") 48 } r <- p.await } yield { r } val