fragmentation/walk

Types

What to do when visiting a fragment.

pub type Visitor(a) {
  Continue(acc: a)
  Stop(acc: a)
}

Constructors

  • Continue(acc: a)

    Continue walking children.

  • Stop(acc: a)

    Stop walking this branch.

Values

pub fn collect(
  root: fragmentation.Fragment,
) -> List(fragmentation.Fragment)

Collect all fragments in a tree, depth-first.

pub fn depth(root: fragmentation.Fragment) -> Int

Get the depth of a fragment tree.

pub fn find(
  root: fragmentation.Fragment,
  predicate: fn(fragmentation.Fragment) -> Bool,
) -> Result(fragmentation.Fragment, Nil)

Find the first fragment matching a predicate, depth-first.

pub fn fold(
  root: fragmentation.Fragment,
  acc: a,
  f: fn(a, fragmentation.Fragment) -> Visitor(a),
) -> a

Fold over all fragments in a tree, depth-first.

Search Document