I have: ox: Option[A]
and oxs: Option[List[A]]
.
I would like to:
Return
ox.get :: oxs.get
if both existed.Return
List(ox.get)
ifox
existed andoxs
did not.Return
oxs.get
ifoxs
existed andox
did not.Return
List()
if both areNone
.
I can achieve this with if
s and matches
. I was just wondering if there was any elegant idiomatic way of doing it?
EDIT: I have tested: List(ox.map(List(_)), oxs).flatten.flatten
and it seems to work for all four cases, but it still looks a bit hard to understand.