Implements foldl iteratively.