how to concatenate option in scala -
what's elegant/right way in scala string concatenate option none renders empty string , variables have value don't wrapped in some("xyz")
case class foo(bar: option[string], bun: option[string]) println(myfoo.bar+ "," + myfoo.bun)
the output want example
hello,
instead of
some(hello),none
to value option
in safe way use getorelse
, provide default argument, used in case option
none
. in example this:
case class foo(bar: option[string], bun: option[string]) println(myfoo.bar.getorelse("") + "," + myfoo.bun.getorelse(""))
then you'll required result
Comments
Post a Comment