Skip to content

Instantly share code, notes, and snippets.

@aappddeevv
Last active February 25, 2021 17:31
Show Gist options
  • Save aappddeevv/727fea0869003ea1da7631b77015f1db to your computer and use it in GitHub Desktop.
Save aappddeevv/727fea0869003ea1da7631b77015f1db to your computer and use it in GitHub Desktop.
package test
import zio._
import zio.console._
type FakeExchange = Has[FakeExchange.Service]
object FakeExchange:
trait Service:
def blah(): UIO[Unit]
def blah(): ZIO[FakeExchange, Nothing, Unit] = ZIO.accessM(_.get.blah())
val fakeExchangeLayer: ZLayer[Any, Nothing, FakeExchange] =
ZLayer.succeed(new FakeExchange.Service {
override def blah() = UIO.unit
})
// main program
object Main extends zio.App:
def run(args: List[String]) =
val infra = ZLayer.requires[zio.console.Console] ++ ZLayer.requires[zio.clock.Clock] ++
ZLayer.requires[zio.blocking.Blocking] ++ ZLayer.requires[zio.random.Random]
type TargetEnv = zio.console.Console & zio.clock.Clock & zio.blocking.Blocking
& FakeExchange & zio.random.Random
val finalLayer: ZLayer[zio.random.Random & zio.console.Console & zio.clock.Clock & zio.blocking.Blocking, Nothing, TargetEnv] =
infra >+> fakeExchangeLayer
val program2: ZIO[TargetEnv, Nothing, Int] = ZIO.succeed(0)
(putStrLn("running...") *> program2).provideCustomLayer(finalLayer).exitCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment