Skip to content

Instantly share code, notes, and snippets.

@nicmart
Last active June 15, 2019 13:59
Show Gist options
  • Save nicmart/6994f496294c3d25c563120fccd4ef94 to your computer and use it in GitHub Desktop.
Save nicmart/6994f496294c3d25c563120fccd4ef94 to your computer and use it in GitHub Desktop.
import scalaz.zio.IO
import scala.io.StdIn
object Example {
case class MyError(text: String)
def readOption(availableOptions: Set[String]): IO[InvalidOption, String] =
IO.effectTotal(StdIn.readLine()).flatMap { input =>
if (availableOptions.contains(input)) IO.succeed(input)
else IO.fail(InvalidOption(input, availableOptions))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment