Skip to content

Instantly share code, notes, and snippets.

@sidnt
Created December 17, 2018 13:11
Show Gist options
  • Save sidnt/9bd6093602cea2b54acafbcca14f63fa to your computer and use it in GitHub Desktop.
Save sidnt/9bd6093602cea2b54acafbcca14f63fa to your computer and use it in GitHub Desktop.
object cli extends App {
val cli: IO[IOException, Unit] = for {
_ <- putStrLn("0. To exit\n1. One\n2. Two\n3. Three\n4. Four\n")
l <- getStrLn
_ <- Try(l.toInt) match {
case Success(c) => {
if(c == 0) IO.now(())
else if (c > 4) putStrLn(s"invalid input: " + c) *> cli
else putStrLn(s"got number: " + c) *> cli
}
case Failure(ex) => putStrLn(s"got exception: " + ex) *> cli
}
} yield ()
def run(args: List[String]): IO[Nothing, ExitStatus] =
cli.attempt.map(_.fold(_ => 1, _ => 0)).map(ExitStatus.ExitNow(_))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment