Skip to content

Instantly share code, notes, and snippets.

@yasuabe
Created March 31, 2019 08:36
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 yasuabe/19243f209c8122dc65eab5351e9d23b5 to your computer and use it in GitHub Desktop.
Save yasuabe/19243f209c8122dc65eab5351e9d23b5 to your computer and use it in GitHub Desktop.
simple test main for ZIO Environment
import scalaz.zio.{App, IO, ZIO}
import scala.io.StdIn
// "org.scalaz" %% "scalaz-zio" % "1.0-RC3"
object SimpleMain extends App {
sealed trait AppError
case object NoValue extends AppError
def valueOf(key: String): ZIO[Map[String, String], AppError, String] =
ZIO.accessM { env =>
ZIO.fromEither(env.get(key).toRight(NoValue))
}
val program: ZIO[Map[String, String], AppError, Unit] = for {
s <- IO.effectTotal(StdIn.readLine())
v <- valueOf(s)
_ <- IO.effectTotal(println(v))
} yield ()
def run(args: List[String]): ZIO[Environment, Nothing, Int] =
program.provide(Map("42" -> "Foo")).fold(_ => 1, _ => 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment