A combination of Rex's answer and Eric's first comment:
Seq("abc", null).map(Option(_)).collect{case Some(x) => x}.mkString(" ")
The first map wraps the values โโleading to Seq[Option[String]] . collect , essentially filter and map , discarding the None values โโand leaving only the expanded values โโof Some .
source share