Skip to content

Instantly share code, notes, and snippets.

@pierangeloc
Created March 8, 2020 13:40
Show Gist options
  • Save pierangeloc/972cc8a4cd3068eabf622c6dab6af5c4 to your computer and use it in GitHub Desktop.
Save pierangeloc/972cc8a4cd3068eabf622c6dab6af5c4 to your computer and use it in GitHub Desktop.
Simple app for sommen/keersommen. In Dutch
import zio.console.Console
import zio.{App, ZIO}
import zio.{console, random}
object Main extends App {
override def run(args: List[String]): ZIO[zio.ZEnv, Nothing, Int] =
prg.forever
val prg = for {
_ <- console.putStrLn("Hier zijn twee nummers, jij moet de som geven")
(n1, n2) <- random.nextInt(10) zip random.nextInt(20)
_ <- console.putStrLn(s"Hoeveel is $n1 + $n2 ?")
res <- getNr.orDie
_ <- if (res == n1 + n2)
console.putStrLn("Goed gedaan!")
else
console.putStrLn(s"niet juist. $n1 + $n2 = ${n1 + n2}, niet $res. Probeer met de volgende.")
} yield ()
val getNr: ZIO[Console, Throwable, Int] = (
for {
str <- console.getStrLn
res <- ZIO.effect(str.toInt)
} yield res
) orElse getNr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment