Created
March 8, 2020 13:40
-
-
Save pierangeloc/972cc8a4cd3068eabf622c6dab6af5c4 to your computer and use it in GitHub Desktop.
Simple app for sommen/keersommen. In Dutch
This file contains 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 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