There are several safe ways to work with Option. If you want to contain the value, I suggest you use either fold, getOrElseor pattern matching.
opt.fold { } { x => }
opt.getOrElse(default)
opt match {
case Some(x) =>
case None =>
}
, Option, map, flatMap, filter / withFilter .. , , -:
opt.map(x => modify(x))
opt.flatMap(x => modifyOpt(x))
opt.filter(x => predicate(x))
for {
x <- optA
y <- optB
if a > b
} yield (a,b)
, , foreach
opt foreach println
for (x <- opt) println(x)