Skip to content

Instantly share code, notes, and snippets.

@dnaumenko
Created February 11, 2020 12:32
Show Gist options
  • Save dnaumenko/0014cc6e0bef7e529451703f24feb7fd to your computer and use it in GitHub Desktop.
Save dnaumenko/0014cc6e0bef7e529451703f24feb7fd to your computer and use it in GitHub Desktop.
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