3 ms·
Options are the most obvious: def foo(opt: Option[Bar]) = opt.map(_.toString).getOrElse("") This non-obviously creates an extra object in the Some case. As o
by kasey_junk 13y ago
Options are the most obvious:
def foo(opt: Option[Bar]) = opt.map(_.toString).getOrElse("")
This non-obviously creates an extra object in the Some case. As opposed to:
if(opt.isDefined) opt.toString else ""
which creates 0. Not a huge deal in this specific case (unless this is a hot call). But this sort of thing is endemic to all of the standard libraries.
Edit -- only 1 extra object, but it is in both the Some & None case (which is sort of the point, it is hard to know with idiomatic Scala)