Skip to content

Instantly share code, notes, and snippets.

@halcat0x15a
Forked from gkojax/aaa.scala
Created July 23, 2012 03:45
Show Gist options
  • Save halcat0x15a/3161904 to your computer and use it in GitHub Desktop.
Save halcat0x15a/3161904 to your computer and use it in GitHub Desktop.
case文とtry catchがネストしてるの
import scala.util.control.Exception._
def string2Int(sizeString: Option[String]): Option[Int] =
sizeString flatMap (a => allCatch opt a.toInt)
string2Int(Option("123")) // Some(123)
string2Int(Option("rrr")) // None
string2Int(None) // None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment