Created
March 31, 2019 08:36
-
-
Save yasuabe/19243f209c8122dc65eab5351e9d23b5 to your computer and use it in GitHub Desktop.
simple test main for ZIO Environment
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
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