lux/codata/struct/stream

Types

Stream

An infinite stream of lazily-evaluated values.

(type: (Stream a)
  (lux/codata/cont;Cont [a (Stream a)]))

Macros

^stream&

## Allows destructuring of streams in pattern-matching expressions.
## Caveat emptor: Only use it for destructuring, and not for testing values within the streams.
(let [(^stream& x y z _tail) (some-stream-func 1 2 3)]
  (func x y z))

Structs

CoMonad<Stream>

(lux/control/comonad;CoMonad Stream)

Functor<Stream>

(lux/control/functor;Functor Stream)

Values

(at idx s)

(All [a] (-> lux;Nat (Stream a) a))

(cycle xs)

Go over the elements of a list forever.

The list shouldn't be empty.

(All [a] (-> (lux;List a) (lux;Maybe (Stream a))))

(drop pred xs)

(All [a] (-> lux;Nat (Stream a) (Stream a)))

(drop-while pred xs)

(All [a] (-> (-> a lux;Bool) (Stream a) (Stream a)))

(filter p xs)

(All [a] (-> (-> a lux;Bool) (Stream a) (Stream a)))

(head s)

(All [a] (-> (Stream a) a))

(iterate f x)

Create a stream by applying a function to a value, and to its result, on and on...

(All [a] (-> (-> a a) a (Stream a)))

(partition p xs)

Split a stream in two based on a predicate.

The left side contains all entries for which the predicate is true.

The right side contains all entries for which the predicate is false.

(All [a] (-> (-> a lux;Bool) (Stream a) [(Stream a) (Stream a)]))

(repeat x)

Repeat a value forever.

(All [a] (-> a (Stream a)))

(split pred xs)

(All [a] (-> lux;Nat (Stream a) [(lux;List a) (Stream a)]))

(split-while pred xs)

(All [a] (-> (-> a lux;Bool) (Stream a) [(lux;List a) (Stream a)]))

(tail s)

(All [a] (-> (Stream a) (Stream a)))

(take pred xs)

(All [a] (-> lux;Nat (Stream a) (lux;List a)))

(take-while pred xs)

(All [a] (-> (-> a lux;Bool) (Stream a) (lux;List a)))

(unfold step init)

A stateful way of infinitely calculating the values of a stream.

(All [a b] (-> (-> a [a b]) a (Stream b)))