scala - Specify default value for collections -


in scala, there idiomatic way specify default value collections when it's empty?

for options, use .getorelse. i'm thinking below:

seq().ifempty(seq("aa", "bb")) // seq("aa", "bb") seq("some", "value").ifempty(seq("aa", "bb")) // seq("some", "value") 

the cleanest way scala (without scalaz) seems be:

option(list).filter(_.nonempty).getorelse(list(1,2,3)) 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

delphi - Indy UDP Read Contents of Adata -