Right now I have many params that can be none, and I want to assign the whole expressiona default value.
Right now I'm doing things like
var name: Option[String] = None
var surname: Option[String] = Some("Smith")
val fullName:String = {
name.map { name =>
surname.map { surname =>
surname + ", " + name
}.getOrElse("unknown")
}.getOrElse("unknown")
}
but it's a bit too verbose. I'd like to know what would be a more idiomatic and elegant way to handle it, ideally it would be something like (it's pseudo code, of course!):
val fullName = (name + ", " + surname).getOrElse("unknown")
or something similar...
(just avoiding the double .getOrElse would be great...)
How about this