Scala - Options - tutorialspoint.com
www.tutorialspoint.com › scala › scala_optionsScala Option [ T ] is a container for zero or one element of a given type. An Option [T] can be either Some [T] or None object, which represents a missing value. For instance, the get method of Scala's Map produces Some (value) if a value corresponding to a given key has been found, or None if the given key is not defined in the Map.
Scala: filtering a collection of Options - Stack Overflow
stackoverflow.com › questions › 7579910Sep 28, 2011 · scala> List(1, 2, 3, 4, "5") collect {case x : Int => x + 42} res1: List[Int] = List(43, 44, 45, 46) collect takes an instance of PartialFunction as argument and applies it to all elements of the collection. In our case the function is defined only for Ints and "5" is filtered. So, collect is a combination of map and filter, which is exactly your case.
Filtering on Scala Option[Set] - Stack Overflow
stackoverflow.com › questions › 10652683May 18, 2012 · val opt: Option[Set[String]] = ... collection.filter { value => opt match { case Some(set) => set.contains(value) case None => true } } If the opt value is Some(...) I want to use the enclosed Set to filter the collection, otherwise I want to include all items in the collection. Is there a better (more idiomatic) way to use the Option (map, filter, getOrElse, etc.)? The opt comes from an optional command line argument containing a list of terms to include. If the command line argument is ...
Filtering on Scala Option[Set] - Stack Overflow
https://stackoverflow.com/questions/10652683val opt: Option[Set[String]] = ... collection.filter { value => opt match { case Some(set) => set.contains(value) case None => true } } If the opt value is Some(...) I want to use the enclosed Set to filter the collection, otherwise I want to include all items in the collection. Is there a better (more idiomatic) way to use the Option (map, filter, getOrElse, etc.)? The opt comes from an optional command line argument containing a list of terms to include.
Scala Standard Library 2.13.6 - scala.Option
www.scala-lang.org › api › 2A less-idiomatic way to use scala.Option values is via pattern matching: val nameMaybe = request getParameter "name" nameMaybe match { case Some (name) => println(name.trim.toUppercase) case None => println("No name value") } Interacting with code that can occasionally return null can be safely wrapped in scala.Option to become None and scala.Some otherwise.