So say we're given a List[String]
and bunch of Option[String]'s
call them a, b, c
. Say I want to append the valid (Some's) Options[String]'s
out of a, b, c
to my existingList[String].
What would be the best way to go about this using immutable structures?
I.e. I know I could use a ListBuffer and do something like:
def foo(a: Option[String], b: Option[String], c: Option[String]) : ListBuffer[String] = {
val existingList = new ListBuffer("hey")
a.map(_ => existingList += _)
b.map(_ => existingList += _)
c.map(_ => existingList += _)
}
but I want to use immutable structures.