scala - Why do some collection classes have an "empty" instance method additionally to the class method? -
both exist example here:
map.empty[int, int] map(1 -> 41).empty set().empty set.empty but here class methods existing:
list.empty //ok list(1,2,3).empty //doesn't exist array.empty //ok array("a").empty //doesn't exist isn't empty perfect case class method (and shouldn't instance method empty deprecated therefore)?
or should empty instance method added classes missing it?
is there language point of view makes difficult having empty class method (e. g. type inference, higher-kinded types, ...).
ps: suggested maps default values harder achieve without instance method empty:
map[int, int](1->2, 21->42).withdefault(_*2).empty what think?
that's true, empty method on class instance. reason why it's required sets , maps because implement builders using method. guess reason why wasn't included elsewhere because wasn't typical use case.
Comments
Post a Comment