A common way to extract the value out of a Scala Option is with a match expression: val res = option match { case Some(i) => i case None => default }. You can also use getOrElse: val res = option.getOrElse(default).
If you want to get the value out of an Option while also applying a function, a match expression can be used: val res = option match { case Some(i) => f(i) case None => default }. Another way is using map followed by getOrElse: val res = option.map(f).getOrElse(default).
An alternative approach is to call fold on the Option: val res = option.fold(default)(f). This applies the function to the value if it's a Some, returning the default if None. The fold function is akin to using it on collections, with a seed value and folding function.
In the fold method, if the Option is a Some, the function is applied to the value, ignoring the default. If it's a None, the default is returned. This differs slightly from traditional folding on collections, but follows a similar syntax.
Collection
[
|
...
]