Created
December 6, 2020 18:11
-
-
Save justinhj/bf7ffacb489491c1d137cad3fd6356b3 to your computer and use it in GitHub Desktop.
How to have multiple of the same ZLayer
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
object Temp { | |
final case class Person(name: String, age: Int) | |
case class Person2(p: Person) | |
val personLayer = ZLayer.succeed(Person("Nero", 4)) | |
val ageLayer = personLayer.project(_.age) | |
val person2Layer = ZLayer.succeed(Person2(Person("Nero2", 8))) | |
val p = (for ( | |
_ <- putStrLn("Should have used better monadic for"); | |
age <- ZIO.access[Has[Int]](_.get); | |
name <- ZIO.access[Has[Person]](_.get.name); | |
name2 <- ZIO.access[Has[Person2]](_.get.p.name); | |
_ <- putStrLn(s"Hello $age $name. Hello name2 $name2") | |
) yield ()).provideLayer(personLayer ++ ageLayer ++ Console.live ++ person2Layer) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment