Some, , None
orElse
def orOption[T](p: (Option[T], Option[T])): Option[T] = {
val (o1, o2) = p
o1 orElse o2
}
However, this decides what to do if there are two values Some:
scala> orOption((Some(1), Some(2)))
res0: Option[Int] = Some(1)
You should probably use pattern matching and then decide what to do if there are two values Some, such as an exception. Alternatively, consider using better coding for the result type than Option.
source
share