Matt Bierner edited this page Aug 2, 2014 · 19 revisions

Nu streams are a simple ordered sequence abstraction. The head of a stream can be accessed in constant time.

Nu streams are lazy. Laziness means that stream elements are only calculated when needed. It also allows most operations to return in constant time.

Nu streams are persistent. Persistence ensures that stream operations never alter the original. You (conceptually) can't mutate a stream after it is created.


To keep Nu small, non-core functionality is split into packages.

API Overview

The Nu API is designed to be small but powerful. The simple set of Nu primitive operations can be composed to build powerful computations.


Operations take arguments in the order best suited for binding. Nu works well with the Khepri bind @, pipe |>, and compose \> operators.

var square := stream.map @ \x -> x * x;

stream.from([1, 2, 3, 4])
    |> square
    |> stream.toArray; // [1, 4, 9, 16]

Interacting With Streams

The Nu APIs are the only supported way to interact with streams. For performance reasons, Nu does not enforces this restriction, but also does not guarantee the correct behavior if you start accessing or transforming stream objects directly.

var s = gen.range();

// Always do this:

// And never this:


Nu expects all functions used by streams to be non-throwing and referentially transparent. Neither is enforced by Nu, but using a non-referentially transparent function may produce unexpected behavior.


Nu routines do not perform any argument validation or error checking. Invalid arguments, such as passing in a non-stream object to an API, will result in a runtime error. This is by design.