graphix-package-list 0.9.0

A dataflow language for UIs and network programming, singly linked list package
Documentation
/// The singly linked list type. Lists support O(1) cons (prepend) and
/// structural sharing -- two lists with a common tail share memory.
type List<'a>;

/// Return an empty list.
val nil: fn(trig: Any) -> List<'a>;

/// Prepend an element to the front of a list. O(1).
val cons: fn(x: 'a, l: List<'a>) -> List<'a>;

/// Return a list containing a single element.
val singleton: fn(x: 'a) -> List<'a>;

/// Return the first element of the list, or null if empty.
val head: fn(l: List<'a>) -> Option<'a>;

/// Return the list without its first element, or null if empty.
val tail: fn(l: List<'a>) -> Option<List<'a>>;

/// Return both the head and tail as a pair, or null if empty.
val uncons: fn(l: List<'a>) -> Option<('a, List<'a>)>;

/// Return true if the list is empty.
val is_empty: fn(l: List<'a>) -> bool;

/// Return the element at position n (0-indexed), or null if out of bounds. O(n).
val nth: fn(l: List<'a>, n: i64) -> Option<'a>;

/// Return the number of elements in the list. O(n).
val len: fn(l: List<'a>) -> i64;

/// Return the list in reverse order. O(n).
val reverse: fn(l: List<'a>) -> List<'a>;

/// Return the first n elements of the list. O(n).
val take: fn(n: i64, l: List<'a>) -> List<'a>;

/// Return the list without its first n elements. O(n).
val drop: fn(n: i64, l: List<'a>) -> List<'a>;

/// Convert a list to an array. O(n).
val to_array: fn(l: List<'a>) -> Array<'a>;

/// Convert an array to a list. O(n).
val from_array: fn(a: Array<'a>) -> List<'a>;

/// Concatenate two or more lists. O(n) in the total size of all lists
/// except the last.
val concat: fn(l: List<'a>, @args: List<'a>) -> List<'a>;

/// Flatten a list of lists into a single list.
val flatten: fn(l: List<List<'a>>) -> List<'a>;

/// Return a new list where each element is the output of f applied to the
/// corresponding element of the input list.
val map: fn(l: List<'a>, f: fn(x: 'a) -> 'b throws 'e) -> List<'b> throws 'e;

/// Return a new list containing only elements where f returned true.
val filter: fn(l: List<'a>, f: fn(x: 'a) -> bool throws 'e) -> List<'a> throws 'e;

/// Return a new list containing the non-null outputs of f.
val filter_map: fn(l: List<'a>, f: fn(x: 'a) -> Option<'b> throws 'e) -> List<'b> throws 'e;

/// Return a new list where f is applied to each element. If f returns a
/// list, its elements are inlined; otherwise the single value is kept.
val flat_map: fn(l: List<'a>, f: fn(x: 'a) -> ['b, List<'b>] throws 'e) -> List<'b> throws 'e;

/// Fold the list from left to right: f(f(f(init, a0), a1), ...).
val fold: fn(l: List<'a>, init: 'b, f: fn(acc: 'b, x: 'a) -> 'b throws 'e) -> 'b throws 'e;

/// Return the first element for which f returns true, or null.
val find: fn(l: List<'a>, f: fn(x: 'a) -> bool throws 'e) -> Option<'a> throws 'e;

/// Return the first non-null output of f.
val find_map: fn(l: List<'a>, f: fn(x: 'a) -> Option<'b> throws 'e) -> Option<'b> throws 'e;

type Direction = [`Ascending, `Descending];

/// Return a sorted copy of the list.
val sort: fn(?#dir: Direction, ?#numeric: bool, l: List<'a>) -> List<'a>;

/// Return a list of (index, element) pairs.
val enumerate: fn(l: List<'a>) -> List<(i64, 'a)>;

/// Zip two lists into a list of pairs. Length is min of the two inputs.
val zip: fn(l0: List<'a>, l1: List<'b>) -> List<('a, 'b)>;

/// Unzip a list of pairs into a pair of lists.
val unzip: fn(l: List<('a, 'b)>) -> (List<'a>, List<'b>);

/// Create a list of n elements where element i is f(i).
val init: fn(n: i64, f: fn(i: i64) -> 'a throws 'e) -> List<'a> throws 'e;

/// Produce an update for every element in the list.
val iter: fn(l: List<'a>) -> 'a;

/// Produce an update for each element, gated by clock updates.
val iterq: fn(#clock: Any, l: List<'a>) -> 'a;