Want to merge val A = Option(Seq(1,2))
and val B = Option(Seq(3,4))
to yield a new option sequence
val C = Option(Seq(1,2,3,4))
This
val C = Option(A.getOrElse(Nil) ++ B.getOrElse(Nil))
,
seems faster and more idiomatic than
val C = Option(A.toList.flatten ++ B.toList.flatten)
But is there a better way? And am I right that getOrElse
is faster and lighter than toList.flatten
?