Use iter().fold() instead of imperative loop.