An alternative to the batteries lazy list library, with generally improved laziness.
and 'a node_t =
| Cons of 'a * 'a t
val nil : 'a t
val singleton : 'a -> 'a t
val repeat : 'a -> 'a t
A constant stream of the input.
val from : (unit -> 'a) -> 'a t
A list whose elements come from unit-delayed expressions.
val of_list : 'a list -> 'a t
Convert an eager list to a lazy one.
val range : int -> int -> int t
The lazy list of values
val unfold : 'a -> ('a -> ('b * 'a) option) -> 'b t
Create a list using a function representing the body of a loop. The loop terminates when the body returns
val hd : 'a t -> 'a
val is_empty : 'a t -> bool
val is_non_empty : 'a t -> bool
val any : ('a -> bool) -> 'a t -> bool
Tests whether any element of the list is satisfied by a predicate.
val all : ('a -> bool) -> 'a t -> bool
Tests whether every element of the list is satisfied by a predicate.
Take elements to the first element for which the predicate fails.
Drop elements until the first element for which the predicate fails.
span p xs is equivalent to
(take_while p xs, drop_while p xs).
Splits a list into those elements which satisfy a predicate and those which don't.
Maps a binary function across corresponding elements of two lists.
Maps a binary function across corresponding elements of two lists, up to the length of the shortest list.
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
val fold_left1 : ('a -> 'a -> 'a) -> 'a t -> 'a
Maps a function across a list whilst accumulating a state value.
As map_accum_l, but also returns the final accumulated value. The input list will be forced only once, even if both components of the pair are forced. However, two passes of the list are still required.
Tests whether every element in the first list is equivalent to the elements in the second list.
val mem : ?cmp:('a -> 'a -> bool) -> 'a -> 'a t -> bool
Based on a partial order. Any element in the first argument which is smaller than an element in the second is removed.
Retains elements in the first argument which are equivalent to some element in the second.
Retains elements in the first argument which are equivalent to some element in the second, and vice versa.
Reduce a list to its maxima according to the partial-order.
val length : 'a t -> int
The following function is sometimes useful for defining recursive lists.
val iter : ('a -> unit) -> 'a t -> unit
Loops a side-effecting procedure over the elements of a list.
val to_list : 'a t -> 'a list
val is_forced : 'a t -> bool
True if the whole list has been forced.
val find_all : ('a -> 'b -> bool) -> 'a list -> 'b t -> 'b list
Find all elements of a set.