1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
6 Typical buffer&#x2013;based incremental I/O is based around a single loop,
7 which reads data from some source (such as a socket or file), transforms
8 it, and generates one or more outputs (such as a line count, HTTP
9 responses, or modified file). Although efficient and safe, these loops are
10 all single&#x2013;purpose; it is difficult or impossible to compose
11 buffer&#x2013;based processing loops.
13 Haskell&#x2019;s concept of &#x201C;lazy I/O&#x201D; allows pure code to
14 operate on data from an external source. However, lazy I/O has several
15 shortcomings. Most notably, resources such as memory and file handles can
16 be retained for arbitrarily long periods of time, causing unpredictable
17 performance and error conditions.
19 Enumerators are an efficient, predictable, and safe alternative to lazy
20 I/O. Discovered by Oleg Kiselyov, they allow large datasets to be processed
21 in near&#x2013;constant space by pure code. Although somewhat more complex
22 to write, using enumerators instead of lazy I/O produces more correct
25 This library contains an enumerator implementation for Haskell, designed to
26 be both simple and efficient. Three core types are defined, along with
27 numerous helper functions:
29 * /Iteratee/: Data sinks, analogous to left folds. Iteratees consume
30 a sequence of /input/ values, and generate a single /output/ value.
31 Many iteratees are designed to perform side effects (such as printing to
32 @stdout@), so they can also be used as monad transformers.
34 * /Enumerator/: Data sources, which generate input sequences. Typical
35 enumerators read from a file handle, socket, random number generator, or
36 other external stream. To operate, enumerators are passed an iteratee, and
37 provide that iteratee with input until either the iteratee has completed its
40 * /Enumeratee/: Data transformers, which operate as both enumerators and
41 iteratees. Enumeratees read from an /outer/ enumerator, and provide the
42 transformed data to an /inner/ iteratee.