Skip to content

Codata.Stream

Potentially infinite sequences of values, represented as Machine<unit, a>, i.e., machines whose input is the unit value.

Elements are produced on demand: head returns the current element, and tail advances the stream to the next one.


Stream

type

A stream is a machine whose input is the unit value, so that elements can be produced on demand.

Stream<a> = Machine<unit, a>Stream<a> = Machine<unit, a>

repeat

Return a stream that repeats the given element indefinitely.

repeat : a -> Stream<a>repeat : a -> Stream<a>

enum_from

Return the stream of consecutive integers starting at n.

enum_from : int32 -> Stream<int32>enum_from : int32 -> Stream<int32>

nats

The stream of all natural numbers, starting at zero.

Equivalently, enum_from(0).

nats : Stream<int32>nats : Stream<int32>

tail

Return the stream without its first element.

tail : Stream<a> -> Stream<a>tail : Stream<a> -> Stream<a>

Return the first element of the stream.

head : Stream<a> -> ahead : Stream<a> -> a

cons

Return a stream whose first element is state, followed by the elements of the given stream.

cons : a -> Stream<a> -> Stream<a>cons : a -> Stream<a> -> Stream<a>

map_stream

Transform each element of a stream using the given function.

map_stream : (a -> b) -> Stream<a> -> Stream<b>map_stream : (a -> b) -> Stream<a> -> Stream<b>

map2_stream

Combine two streams elementwise using the given function.

map2_stream : (a -> b -> c) -> Stream<a> -> Stream<b> -> Stream<c>map2_stream : (a -> b -> c) -> Stream<a> -> Stream<b> -> Stream<c>

map3_stream

Combine three streams elementwise using the given function.

map3_stream : (a -> b -> c -> d) -> Stream<a> -> Stream<b> -> Stream<c> -> Stream<d>map3_stream : (a -> b -> c -> d) -> Stream<a> -> Stream<b> -> Stream<c> -> Stream<d>

map4_stream

Combine four streams elementwise using the given function.

map4_stream : (a -> b -> c -> d -> e) -> Stream<a> -> Stream<b> -> Stream<c> -> Stream<d> -> Stream<e>map4_stream : (a -> b -> c -> d -> e) -> Stream<a> -> Stream<b> -> Stream<c> -> Stream<d> -> Stream<e>

zip_streams

Combine the elements of two streams into a stream of pairs.

Equivalent to map2_stream(fn(a, b) => (a, b), s1, s2).

zip_streams : Stream<a> -> Stream<b> -> Stream<(a, b)>zip_streams : Stream<a> -> Stream<b> -> Stream<(a, b)>

zip3_streams

Combine the elements of three streams into a stream of triples.

Equivalent to map3_stream(fn(a, b, c) => (a, b, c), s1, s2, s3).

zip3_streams : Stream<a> -> Stream<b> -> Stream<c> -> Stream<(a, b, c)>zip3_streams : Stream<a> -> Stream<b> -> Stream<c> -> Stream<(a, b, c)>

zip4_streams

Combine the elements of four streams into a stream of quadruples.

Equivalent to map4_stream(fn(a, b, c, d) => (a, b, c, d), s1, s2, s3, s4).

zip4_streams : Stream<a> -> Stream<b> -> Stream<c> -> Stream<d> -> Stream<(a, b, c, d)>zip4_streams : Stream<a> -> Stream<b> -> Stream<c> -> Stream<d> -> Stream<(a, b, c, d)>

merge_with

Interleave two streams, applying fa to the elements of the first stream and fb to the elements of the second.

The elements are drawn alternately from s1 and s2, beginning with s1.

merge_with : (a -> c) -> (b -> c) -> Stream<a> -> Stream<b> -> Stream<c>merge_with : (a -> c) -> (b -> c) -> Stream<a> -> Stream<b> -> Stream<c>

merge

Interleave two streams, alternating between their elements.

Equivalent to merge_with(identity, identity, s1, s2).

merge : Stream<a> -> Stream<a> -> Stream<a>merge : Stream<a> -> Stream<a> -> Stream<a>

scan

Fold over a stream, returning a stream of successive accumulator values.

The first element of the result is the initial value seed; each subsequent element is obtained by applying transition to the next element of the stream and the previous accumulator.

scan : (i -> o -> o) -> o -> Stream<i> -> Stream<o>scan : (i -> o -> o) -> o -> Stream<i> -> Stream<o>