Hostname: page-component-77c78cf97d-hf2s2 Total loading time: 0 Render date: 2026-05-04T07:05:52.880Z Has data issue: false hasContentIssue false

The essence of the Iterator pattern

Published online by Cambridge University Press:  01 July 2009

JEREMY GIBBONS
Affiliation:
Oxford University Computing Laboratory, Wolfson Building, Parks Road, Oxford OX1 3QD, UK (e-mail: jeremy.gibbons@comlab.ox.ac.uk, bruno.oliveira@comlab.ox.ac.uk)
BRUNO C. d. S. OLIVEIRA
Affiliation:
Oxford University Computing Laboratory, Wolfson Building, Parks Road, Oxford OX1 3QD, UK (e-mail: jeremy.gibbons@comlab.ox.ac.uk, bruno.oliveira@comlab.ox.ac.uk)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the 'Save PDF' action button.

The Iterator pattern gives a clean interface for element-by-element access to a collection, independent of the collection's shape. Imperative iterations using the pattern have two simultaneous aspects: mapping and accumulating. Various existing functional models of iteration capture one or other of these aspects, but not both simultaneously. We argue that C. McBride and R. Paterson's applicative functors (Applicative programming with effects, J. Funct. Program., 18 (1): 1–13, 2008), and in particular the corresponding traverse operator, do exactly this, and therefore capture the essence of the Iterator pattern. Moreover, they do so in a way that nicely supports modular programming. We present some axioms for traversal, discuss modularity concerns and illustrate with a simple example, the wordcount problem.

Information

Type
Articles
Copyright
Copyright © Cambridge University Press 2009
Submit a response

Discussions

No Discussions have been published for this article.