Skip to content

Instantly share code, notes, and snippets.

@justinhj
Created December 6, 2020 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinhj/bf7ffacb489491c1d137cad3fd6356b3 to your computer and use it in GitHub Desktop.
Save justinhj/bf7ffacb489491c1d137cad3fd6356b3 to your computer and use it in GitHub Desktop.
How to have multiple of the same ZLayer
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