Section 2.9.2 - Eliminating Indirections

Lens was a godsend here - before finding mapAccumLOf I had much, much
more complicated incantations involving foldl and the state monad.