std.stream

Lazy stream type.

Types

type Stream a = Lazy (Stream_ a)

Values

let empty : forall a . Stream a

let from f : forall a . (Int -> Option a) -> Stream a

let of xs : forall a . Array a -> Stream a

let repeat x : forall a . a -> Stream a

let take n xs : forall a . Int -> Stream a -> Stream a

Takes the first n elements of xs.

let { ? } = import! std.effect
let stream @ { take, repeat, empty, ? } = import! std.stream
let { assert_eq, ? } = import! std.test

seq assert_eq (take 0 (repeat "abc")) empty
assert_eq (take 3 (repeat 1)) (stream.of [1, 1, 1])

let next stream : forall a . Stream a -> Option a

let is_empty stream : forall a . Stream a -> Bool

Checks if the stream is empty

let stream = import! std.stream
let { assert_eq } = import! std.test

assert_eq (stream.is_empty stream.empty) True

let to_list : forall a . Stream a -> List a

Converts the Stream to a List

let stream = import! std.stream
let list @ { ? } = import! std.list
let { assert_eq } = import! std.test

assert_eq (stream.to_list (stream.of ["a", "b"])) (list.of ["a", "b"])

let zip_with f xs ys : forall c b a . (a -> b -> c) -> Stream a -> Stream b -> Stream c

let eq ?eq : forall a . [Eq a] -> Eq (Stream a)

Eq a defines equality (==) on a

let ord ?ord : forall a . [Ord a] -> Ord (Stream a)

Ord a defines an ordering on a

let show ?d : forall a . [Show a] -> Show (Stream a)

Show a represents a conversion function from a to a readable string.

A Functor represents an action on a parameterized type which does not change the structure with the mapped type.

The following laws should hold:

  • map id == id
  • map (f << g) == map f << map g

Operations over a data structure that can be folded which means that a functions gets called on each element to reduce the structure to a single value (Array, List and Map are all Foldable)

let monoid : forall a . Monoid (Stream a)

Monoid a represents an semigroup an which has an identity. This means the following additional laws must hold:

  • forall x . append x empty == x
  • forall x . append empty x == x

let semigroup : forall a . Semigroup (Stream a)

Semigroup a represents an associative operation on a. This means the following laws must hold:

  • forall x . append x (append y z) == append (append x y) z