Skip to content

Instantly share code, notes, and snippets.

@zjhmale
Last active August 29, 2015 14:21
Show Gist options
  • Save zjhmale/22989a9f2a0bc1bd0fe2 to your computer and use it in GitHub Desktop.
Save zjhmale/22989a9f2a0bc1bd0fe2 to your computer and use it in GitHub Desktop.
scala option map filter
val a : Option[String] = Some("333")
//a: Option[String] = Some(333)
a.filter(_.length > 1).map(_.length)
//Option[Int] = Some(3)
a.filter(_.length > 6).map(_.length)
//Option[Int] = None
//filter and map function is just for Option type it's just a monad
//def filter(p: A => Boolean): Option[A]
//def map[B](f: A => B): Option[B]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment