Created
December 17, 2018 13:11
-
-
Save sidnt/9bd6093602cea2b54acafbcca14f63fa to your computer and use it in GitHub Desktop.
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
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