What might be the most idiomatic way for turning any scala collection into an Option
of the same collection, whereas when the collection is empty, the option would be None
and otherwise just a Some
of the original?
Oh, and without making scala create a memory copy of the entire collection for that humble conversion.
Option.apply
is suited for translating null
to Option
of type None
, a nice legacy-wrangling utility, but useless for idiomatic scala seeking the following semantics:
val some = Option(List(3,4,5))
val none = Option(List()) // seeking None, rather than Some(List()) here