qcheck/tree

Trees

This module contains functions for creating and manipulating shrink trees.

They are mostly inteded for internal use or “advanced” manual construction of generators. In typical usage, you will probably not need to interact with these functions much, if at all. As such, they are currently mostly undocumented.

In fact, if you are using these functions a lot, file a issue on GitHub and let me know if there are any generator combinators that you’re missing.

There are functions for dealing with the Tree type directly, but they are low-level and you should not need to use them much.

Types

pub type Tree(a) {
  Tree(a, Yielder(Tree(a)))
}

Constructors

  • Tree(a, Yielder(Tree(a)))

Functions

pub fn apply(f: Tree(fn(a) -> b), x: Tree(a)) -> Tree(b)
pub fn bind(tree: Tree(a), f: fn(a) -> Tree(b)) -> Tree(b)
pub fn collect(tree: Tree(a), f: fn(a) -> b) -> List(b)

Collect values of the tree into a list, while processing them with the mapping given function f.

pub fn map(tree: Tree(a), f: fn(a) -> b) -> Tree(b)
pub fn map2(a: Tree(a), b: Tree(b), f: fn(a, b) -> c) -> Tree(c)
pub fn new(x: a, shrink: fn(a) -> Yielder(a)) -> Tree(a)
pub fn option(tree: Tree(a)) -> Tree(Option(a))
pub fn return(x: a) -> Tree(a)
pub fn sequence_trees(l: List(Tree(a))) -> Tree(List(a))

sequence_trees(list_of_trees) sequences a list of trees into a tree of lists.

pub fn to_string(
  tree: Tree(a),
  a_to_string: fn(a) -> String,
) -> String

to_string(tree, element_to_string) converts a tree into an unspecified string representation.

  • element_to_string: a function that converts individual elements of the tree to strings.
pub fn to_string_max_depth(
  tree: Tree(a),
  a_to_string: fn(a) -> String,
  max_depth: Int,
) -> String

Like to_string but with a configurable max_depth.

Search Document