Skip to content

Iteratee

A resumable stream consumer that processes externally supplied input chunks and returns a result or a continuation requesting more input.

Version
v1 · 2026-10-03 · History
Domain-specific #
13351
Aliases
Iteratee stream consumer

Core Idea

An iteratee is a resumable stream consumer: it accepts input supplied by a producer, advances its state, and returns either a completed result or a continuation that needs more input. The producer, often called an enumerator, can read from a file or other source; an optional enumeratee transforms chunks between source and consumer. The identity is this control separation, not any one library's exact state constructors.

How would you explain it like I'm…

The 'More, Please!' Helper

Imagine a helper who eats snacks you hand them, one bite at a time. The helper doesn't go to the snack cupboard themselves; they just wait for you. After each bite they say either 'I'm done, here's my answer' or 'I'm ready for more'. You can also tell them 'that's all the snacks'.

Feed-Me-More Data Eater

In programming, data often arrives in pieces, like a file read bit by bit or messages coming over the internet. An iteratee is a piece of a program that eats data. Someone else, called an enumerator, feeds it chunks and finally tells it 'that's the end'. After each chunk, the iteratee either gives back a finished answer or returns a version of itself that is waiting for more. It can be as simple as counting spaces or as complex as understanding a whole language.

Resumable Stream Consumer

An iteratee is a way to write a stream consumer as a value. You can feed it more input, it advances its computation, and it returns either a completed result or a continuation, meaning a paused version that awaits more input. A separate producer, often called an enumerator, supplies chunks of data and signals the end of input. This separates producing a stream from consuming it: the iteratee doesn't open or read the file or socket itself, it only says how to handle what arrives. Different implementations name their states differently, for example 'done' versus 'continue', or Done, NeedInput, NeedIO, and Failed. What matters is that consumption is externally fed and resumable. Stream transformers called enumeratees can sit between the source and the consumer, but individual iteratees don't require them.

 

An iteratee models incremental stream consumption as a first-class value in a state-machine style. Supplying a chunk of input steps the computation, which yields either a final result or a continuation awaiting further input; an end-of-input indication lets it finish. The enumerator, the producer, drives the iteratee by feeding it data, so the consumer only describes how to process whatever arrives rather than owning or pulling from a resource. Kiselyov's design frames this as a separation of stream production and consumption, using done and continuation states plus a message/error channel. Other implementations, such as a Stanford teaching version with Done, NeedInput, NeedIO, and Failed, differ in labels but preserve resumable, externally fed consumption. Enumeratees transform streams between producer and consumer and compose with iteratees, but are not part of every iteratee.

Scope of Application

Iteratees can count, parse, or transform large inputs without first requiring the whole stream as one value. An original example counts whitespace from file-fed character chunks; a teaching implementation reads one line and returns residual bytes after its delimiter. In a well-designed file enumerator, the producer can close its resource once the consumer finishes, including early completion. That resource guarantee is an implementation property, not automatic for every iteratee.

Clarity

Distinguish the consumer, producer, and optional transformer. The consumer does not normally own the file handle in the cited pattern. Continue, Done, Error, NeedIO, and residual-chunk encodings vary by library; only resumption and completion feedback are invariant. A whole-list function or a handle-reading loop may compute the same answer without instantiating this interface.

Manages Complexity

The producer can feed small chunks while the consumer carries only its current state, and transformers can filter or decode incrementally. This separates parsing logic from source management. It does not itself guarantee constant memory: a consumer that accumulates an unbounded line or list can still grow without limit, and a parser stopping mid-chunk must preserve the unused suffix.

Abstract Reasoning

Each supplied chunk sends the consumer to a new state. If more input is requested, the producer continues; if a result is returned, it can stop. A line reader can finish at a newline while returning the chunk's remaining bytes for the next parser. Exact Haskell constructors differ, but the step-and-resume relation is stable.

Knowledge Transfer

For another streaming library, find the resumable consumer state, who supplies input, how completion is signaled, and how errors and unconsumed bytes are handled. Do not equate iteratee with the entire event-time Stream Processing system or with the live Fold prime, which is physical bending. This draft is staged unparented because no current live node supplies the specific consumer-interface genus.

Neighborhood in Abstraction Space

Iteratee sits in a sparse region of the domain-specific corpus (70th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Program Execution & Runtime Concepts (34 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14