I am developing some code using Scala, and I am trying to reasonably allow basic conversion between collections containing some Option[T] .
Say we have the following list
val list: List[(A, Option[B])] =
and we want to apply the conversion to list to get the following list
val transformed: List[(B, A)]
for all Option[B] , which are evaluated to Some[B] . The best way I've found for this is to apply the following chain of transformations:
val transformed = list.filter(_.isDefined) .map { case (a, Some(b)) => (b, a) }
However, I feel that something is missing. What is the best way to handle Option[T] s?
source share