Stream (abstract data type)

In type theory and functional programming, a stream is a potentially infinite analog of a list, given by the coinductive definition:

data Stream α = Nil | Cons α (Stream α)

Generating and computing with streams requires lazy evaluation, either implicitly in a lazily evaluated language or by creating and forcing thunks in an eager language. In total languages they must be defined as codata and can be iterated over using (guarded) corecursion.

UML package diagram of the stream hierarchy in .NET

Java provides the

Stream interface under thejava.util.stream namespace.

JavaScript provides theReadableStream,WritableStream andTransformStream interfaces.

Python have theStreamReader andStreamWriter classes in theasyncio module.

.NET provides the abstract classStream which is implemented by classes such asFileStream andMemoryStream.

In Rust a struct can implement theRead trait. There is also theCursor struct wraps an in-memory buffer.

See also

References


Uses material from the Wikipedia article Stream (abstract data type), released under the CC BY-SA 4.0 license.