spekk.trees.core

spekk.trees.core#

Functions that operate on trees.

Functions

are_equal(tree1, tree2, is_leaf[, ...])

Return True if the two trees has the same structure and each leaf are equal according to leafs_are_equal (defaults to == operator).

filter(tree, is_leaf, predicate[, path])

Remove all subtrees for which the predicate returns False.

get(tree, path[, default])

Get the subtree at the given path.

has_path(tree, path)

Return True if the given path exists in the tree.

leaves(tree, is_leaf[, path])

Traverse a tree and yield all leaves as TraversalItem objects.

merge(t1, t2[, preserve_order])

Merge two trees (assuming this is possible).

remove(tree, path)

Remove the value of the subtree at the given path.

set(tree, value, path)

Set the value of the subtree at the given path.

traverse(tree, is_leaf[, path])

Traverse a tree and yield all nodes (subtrees and leaves) as TraversalItem objects.

update(tree, f, path)

Update the subtree at the given path.

update_leaves(tree, is_leaf, f[, path])

Apply f to all leaves in the tree.

Classes

TraversalItem(value, path, is_leaf)

An object returned from the traverse() and leaves() generator functions.