Skip to content

Instantly share code, notes, and snippets.

@torbjornvatn
Created June 23, 2011 05:48
Show Gist options
  • Save torbjornvatn/1041978 to your computer and use it in GitHub Desktop.
Save torbjornvatn/1041978 to your computer and use it in GitHub Desktop.
Compact Scala Option
scala> val myOpt:Option[Int] = Some(1234)
myOpt: Option[Int] = Some(1234)
scala> myOpt.map { _.toString.reverse.mkString("*")}.getOrElse("unknown")
res2: String = 4*3*2*1
scala> val myOpt:Option[Int] = None
myOpt: Option[Int] = None
scala> myOpt.map { _.toString.reverse.mkString("*")}.getOrElse("unknown")
res3: String = unknown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment