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

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -