rodoherty1 rodoherty1 - 1 month ago 6
Scala Question

Scala: Concatonate two instances of Option[List]

Given the following:

val l1 = Some(List(1))
val l2 = Some(List(2))


I would like to concatenating
l1
and
l2
so that I get a
List(1, 2)
or
Nil
if both Options are equal to
None
.

I'm happy to use scalaz if there is an elegant solution there.

Answer

l1.getOrElse(Nil) ::: l2.getOrElse(Nil)

Comments