Let's say you've got Option[A] you need to convert it to
Some(b : B) for None
and to
None for Some(a : A).
Is there code that does this already? I can write some, but what's the most straightforward way?
Let's say you've got Option[A] you need to convert it to
Some(b : B) for None
and to
None for Some(a : A).
Is there code that does this already? I can write some, but what's the most straightforward way?
The most straightforward way is :
val b : B = new B()
val newA: Option[B] = a.fold(Some(b))(_ => None)