Created
February 11, 2020 12:32
-
-
Save dnaumenko/0014cc6e0bef7e529451703f24feb7fd to your computer and use it in GitHub Desktop.
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
| private final class EnvCtx[Ctx, +A] (zio: RIO[Ctx, A]) extends Env[Ctx, A] { | |
| override def run: RIO[Ctx, A] = zio | |
| override def map[B](f: A => B) = ... | |
| override def flatMap[B](f: A => Env[Ctx, B]) = ... | |
| override def unsafeRunSync(env: Ctx): A = { | |
| Exit.fromZIOExit(runtime.unsafeRunSync(zio.provide(env))) match { | |
| case Exit.Success(value) => value | |
| case Exit.Error(throwable) => throw throwable | |
| case Exit.Termination(throwable) => throw throwable | |
| } | |
| } | |
| } | |
| object EnvCtx { | |
| def apply[R, A](body: => A): Env[R, A] = ofZIO(ZIO(body)) | |
| def pure[R, A](x: A): Env[R, A] = ofZIO(ZIO.succeed(x)) | |
| def delay[R, A](x: A): Env[R, A] = ofZIO(ZIO.effect(x)) | |
| def ofZIO[R, A](zio: RIO[R, A]): Env[R, A] = EnvCtx(zio) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment