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
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