scala - Specify default value for collections -
in scala, there idiomatic way specify default value collections when it's empty?
for option
s, 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
Post a Comment