If I have a case class defined as:
case class Foo(bar: Option[String])
and a variable baz: Option[Foo]
, what's the most idiomatic way to extract bar
from baz
while providing a default value like an empty string?
Right now, I have
baz.fold("")(_.bar.getOrElse(""))
but having the empty string in there twice makes me think there's a better way.