News for hackers. Stuff that matters.
Re:Scala Best Practices by orp on Saturday November 01, 2014 @01:03AM (#8542243)
Hi,

Quick comment on item 2.3: SHOULD NOT update a var using loops or conditions.

you conclude that this expression is the best option: val sum = elements.map(_.value).sum

This expression is not equivalent to the previous options in performance and memory, as the map expression will create a entire new sequence.

For large sequences, a better option is to write: val sum = elements.view.map(_.value).sum

There are no comments on this comment yet.