Re:Scala – 1 Star Would Not Program Again
by kasey_junk on Tuesday January 14, 2014 @02:00PM
(#7058959)
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)
Can you give an example of when you had to do this? I often wonder about the performance costs of chaining together several collection API calls.