Top "Scala-option" questions

Option in the Scala language is a container for zero or one element of a given type.

Check for None in Scala Option type isEmpty method

I'm using the Option Type's isEmpty method to check if there is no value. I do not want to use …

scala scala-option
Wrapping null-returning method in Java with Option in Scala?

Suppose I have a method session.get(str: String): String but you don't know whether it will return you a …

java scala scala-option
How to flatten list of options using higher order functions?

Using Scala 2.7.7: If I have a list of Options, I can flatten them using a for-comprehension: val listOfOptions = List(None, …

scala scala-option
Is there a scala identity function?

If I have something like a List[Option[A]] and I want to convert this into a List[A], the …

scala functional-programming scala-option
How to transform Scala collection of Option[X] to collection of X

I'm starting to explore Scala, and one of the things I'm intrigued by is the Option type and the promise …

scala scala-collections scala-option
Composing Option with List in for-comprehension gives type mismatch depending on order

Why does this construction cause a Type Mismatch error in Scala? for (first <- Some(1); second <- List(1,2,3)) …

scala for-loop type-mismatch for-comprehension scala-option
Scala Option - Getting rid of if (opt.isDefined) {}

My code is becoming littered with the following code pattern: val opt = somethingReturningAnOpt if (opt.isDefinedAt) { val actualThingIWant = opt.get } …

scala scala-option
Why is foreach better than get for Scala Options?

Why using foreach, map, flatMap etc. are considered better than using get for Scala Options? If I useisEmpty I can …

scala scala-option
How to get an Option from index in Collection in Scala?

Is there a way, only using the Scala collection API, to get an Option in a List when trying to …

scala scala-option
How can I (best) convert an Option into a Try?

How can I (best) convert an Option returned by a method call into a Try (by preference, although an Either …

scala scala-option