What is the function that I should pass to ‘traverse’ (from the essence of the iterator pattern) such that I can accumulate state based on each of the original elements and then map based on the original elements and the state so far.
In ‘collect’ and ‘disperse’ only either the mapping depends on the state or the state depends on the element, but not both at the same time.
The table at http://etorreborre.blogspot.co.uk/2011/06/essence-of-iterator-pattern.html appears to say that I should use ‘traverse’ but traverse is the function that implements all the others, so I’m a bit lost.
When you use the
traversemethod with a function returning aState, you get exactly what you want: