differance

Types

A difference list is a way of representing a list that allows for the use of the “snoc” and “append” operations in constant O(1) time.

pub type DList(a) =
  fn(List(a)) -> List(a)

Functions

pub fn append(
  first: fn(List(a)) -> List(a),
  with second: fn(List(a)) -> List(a),
) -> fn(List(a)) -> List(a)

Get the diff that represents the concatenation of first and second

pub fn concat(
  diffs: List(fn(List(a)) -> List(a)),
) -> fn(List(a)) -> List(a)

Get a diff that represents the concatenation of all given diff

pub fn empty() -> fn(List(a)) -> List(a)

An empty difference list (DList, append, empty) is a monoid

pub fn fold(
  over diff: fn(List(a)) -> List(a),
  from initial: b,
  with f: fn(b, a) -> b,
) -> b

Reduce a diff into a single value by calling a given function on each element from left to right

pub fn fold_right(
  over diff: fn(List(a)) -> List(a),
  from initial: b,
  with f: fn(b, a) -> b,
) -> b

Reduce a diff into a single value by calling a given function on each element from right to left

pub fn from_list(list: List(a)) -> fn(List(a)) -> List(a)

Creates a diff representing list

pub fn head(of diff: fn(List(a)) -> List(a)) -> Option(a)

Returns the first element of a diff wrapped in an option

pub fn length(of diff: fn(List(a)) -> List(a)) -> Int

Counts the number of elements in a given diff.

pub fn map(
  diff: fn(List(a)) -> List(a),
  with f: fn(a) -> b,
) -> fn(List(b)) -> List(b)

Creates a new diff whose elements are the result of applying the given function to the elements of the original list

pub fn map2(
  diff1: fn(List(a)) -> List(a),
  diff2: fn(List(b)) -> List(b),
  with f: fn(a, b) -> c,
) -> fn(List(c)) -> List(c)

Combines two diffs into a single diff using the given function

If a diff is longer than the other the extra elements are dropped

pub fn reverse(
  diff: fn(List(a)) -> List(a),
) -> fn(List(a)) -> List(a)

Creates a new diff from a given diff containing the same elements but in the opposite order.

pub fn singleton(elem: a) -> fn(List(a)) -> List(a)

A diff with a single element

pub fn tail(
  of diff: fn(List(a)) -> List(a),
) -> Option(fn(List(a)) -> List(a))

Returns a diff with the same elements excluding the first one wrapped in an Option

pub fn to_list(diff: fn(List(a)) -> List(a)) -> List(a)

Collapses a diff into a list

pub fn zip(
  diff: fn(List(a)) -> List(a),
  with other: fn(List(b)) -> List(b),
) -> fn(List(#(a, b))) -> List(#(a, b))

Combines two diffs into a diff of tuples of their elements

If a diff is longer than the other the extra elements are dropped

Search Document