ZIO Cheat Sheet

November 25, 2018

https://github.com/zio/zio

sbt configuration

/***
libraryDependencies += "dev.zio" %% "zio" % "1.0.0-RC10-1"
*/

Type aliases

A program with side-effects

val program: zio.Task[Unit] =
  for {
    now <- zio.ZIO.effect { new java.util.Date() }
    _   <- zio.ZIO.effect { println(now) }
  } yield ()

Running the program

val runtime = new zio.DefaultRuntime {}

runtime.unsafeRun(program)

Demo

This file is literate Scala, and can be run using Codedown:

$ curl -s https://earldouglas.com/posts/reference/zio.md |
  codedown scala > script.scala
$ sbt -Dsbt.main.class=sbt.ScriptMain script.scala
Sat Jul 13 13:55:05 MDT 2019