So right now I have a list of a object with a Optional Field like this in scala
case class Foo(
id: String,
description: String,
OptionalTag: Option[String],
)
What I want is to iterate through the list of objects and only get the Optional Tags if they exists, my current approach is this
Tags = listOfFoos.map(foo =>
if (foo.OptionalTag.isDefined) {
foo.OptionalTag.get
} else {
""
}
).filter(_ != "" -> "")
However Im sure theres a better way to do this then go over the entire list twice but I can not figure it out.