10 ms·
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
by orp 12y ago
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