package lwd

  1. Overview
  2. Docs
Lightweight reactive documents

Install

Dune Dependency

Authors

Maintainers

Sources

nottui-lwt-0.2.tbz
sha256=09d9ebbffb172789938869136562d7b70818d6167f4bb05b8b187c08af3b3221
sha512=a88cfbdce6ecd280d10c34a712b685b44c712981ac85e500dab1518e513f9ac0bc02d0469184df927ab86f29e330b3439bb7eb8fb9a11f90a0a37bf46fdaa53e

doc/lwd/Lwd_seq/index.html

Module Lwd_seqSource

Sequence manipulation

Lwd_seq is an ordered collection with a pure interface. Changes to collections are easy to track.

A collection can be transformed with the usual map, filter and fold combinators. If the collection is updated, shared elements (in the sense of physical sharing), the result of the previous transformation will be reused for these elements.

The book-keeping overhead is O(n) in the number of changes, so O(1) per element.

Sourcetype +'a t
Sourcetype +'a seq = 'a t

The type of sequences

Primitive constructors

Sourceval empty : 'a seq

A sequence with no element.

Sourceval element : 'a -> 'a seq

A singleton sequence. The physical identity of the element is considered when reusing previous computations.

If you do:

let x1 = element x
  let x2 = element x

Then x1 and x2 are seen as different elements and no sharing will be done during transformation.

Sourceval concat : 'a seq -> 'a seq -> 'a seq

Concatenate two sequences into a bigger one. As for element, the physical identity of a sequence is considered for reuse.

Looking at sequence contents

Sourcetype ('a, 'b) view =
  1. | Empty
  2. | Element of 'a
  3. | Concat of 'b * 'b
Sourceval view : 'a seq -> ('a, 'a seq) view

View how a sequence is defined

Conversion between sequences, lists and arrays

Sourceval transform_list : 'a list -> ('a -> 'b seq) -> 'b seq

Produce a sequence by transforming each element of a list and concatenating all results.

Sourceval transform_array : 'a array -> ('a -> 'b seq) -> 'b seq

Produce a sequence by transforming each element of an array and concatenating all results.

Sourceval of_list : 'a list -> 'a seq

Produce a sequence from a list

Sourceval of_array : 'a array -> 'a seq

Produce a sequence from an array

Sourceval to_list : 'a seq -> 'a list

Produce a list from a sequence

Sourceval to_array : 'a seq -> 'a array

Produce an array from a sequence

Balanced variant of sequences

Sourcemodule Balanced : sig ... end

A variant of the sequence type that guarantees that the depth of a transformation, measured as the number of nested concat nodes, grows in O(log n) where n is the number of elements in the sequnce.

Transforming sequences

All sequences live in Lwd monad: if a sequence changes slightly, parts that have not changed will not be re-transformed.

Sourceval fold : map:('a -> 'b) -> reduce:('b -> 'b -> 'b) -> 'a seq Lwd.t -> 'b option Lwd.t

fold ~map ~reduce transforms a sequence. If the sequence is non-empty, the map function is applied to element nodes and the reduce function is used to combine transformed concatenated nodes. If the sequence is empty, None is returned.

Sourceval fold_monoid : ('a -> 'b) -> 'b Lwd_utils.monoid -> 'a seq Lwd.t -> 'b Lwd.t

Like fold, but reduction and default value are defined by a monoid

Sourceval map : ('a -> 'b) -> 'a seq Lwd.t -> 'b seq Lwd.t

map f transforms a sequence by applying f to each element.

Sourceval filter : ('a -> bool) -> 'a seq Lwd.t -> 'a seq Lwd.t

filter p transforms a sequence by keeping elements that satisfies p.

Sourceval filter_map : ('a -> 'b option) -> 'a seq Lwd.t -> 'b seq Lwd.t

Filter and map elements at the same time

Sourceval lift : 'a Lwd.t seq Lwd.t -> 'a seq Lwd.t

Remove a layer of Lwd inside a sequence.

Sourceval bind : 'a seq Lwd.t -> ('a -> 'b seq Lwd.t) -> 'b seq Lwd.t

Sequence forms a monad too...

Sourceval seq_bind : 'a seq Lwd.t -> ('a -> 'b seq) -> 'b seq Lwd.t

Sequence forms a monad too...

Sourceval monoid : 'a t Lwd_utils.monoid

Monoid instance for sequences

Sourceval lwd_monoid : 'a t Lwd.t Lwd_utils.monoid

Monoid instance for reactive sequences

Low-level interface for observing changes

Sourcemodule Reducer : sig ... end
OCaml

Innovation. Community. Security.