Scala headOption example

The scala collections API provides a function called “headOption”, which returns a Some(value) if there is an item in a list, and a “None” otherwise. Observe: scala> List(1).headOption res35: Option[Int] = Some(1) scala> List().headOption res36: Option[Nothing] = None It may not be immediately obvious why this is useful, especially if you’re coming from Java, or …