An extractor for Source
Collects a set of objects from all sub-expressions
Counts how many times the predicate holds in sub-expressions
Computes the depth of the tree
Checks if the predicate holds in some sub-expression
Returns a set of all sub-expressions matching the predicate
Does a right tree fold
Does a right tree fold
A right tree fold applies the input function to the subnodes first (from left to right), and combine the results along with the current node value.
a function that takes the current node and the seq of results form the Sources.
The value on which to apply the fold.
The expression after applying f
on all Sources.
the computation is lazy, hence you should not rely on side-effects of f
Computes the size of a tree
Applies functions and combines results in a generic way
Applies functions and combines results in a generic way
Start with an initial value, and apply functions to nodes before and after the recursion in the children. Combine the results of all children and apply a final function on the resulting node.
a function applied on a node before doing a recursion in the children
a function applied to the node built from the recursive application to all children
a function to combine the resulting values from all children with the current node
the initial value
the expression on which to apply the transform
Given a tree toSearch
present in treeToLookInto
, if treeToLookInto
has the same shape as treeToExtract
,
returns the matching expression in treeToExtract
.
Post-transformation of the tree.
Post-transformation of the tree.
Takes a partial function of replacements. Substitutes after recurring down the trees.
Supports two modes :
Add(a, Minus(b, c)) with replacements: Minus(b,c) -> z, Minus(e,c) -> d, b -> e
will yield:
Add(a, Minus(e, c))
Add(a, Minus(b, c)) with replacements: Minus(e,c) -> d, b -> e, d -> f
will yield:
Add(a, f)
The mode with applyRec true can diverge if f is not well formed (i.e. not convergent)
Post-traversal of the tree.
Post-traversal of the tree.
Invokes the input function on every node after visiting children.
e.g.
Add(a, Minus(b, c))
will yield, in order:
f(a), f(b), f(c), f(Minus(b, c)), f(Add(a, Minus(b, c)))
a function to apply on each node of the expression
the expression to traverse
Pre-transformation of the tree.
Pre-transformation of the tree.
Takes a partial function of replacements and substitute before recursing down the trees.
Supports two modes :
e.g.
Add(a, Minus(b, c)) with replacements: Minus(b,c) -> d, b -> e, d -> f
will yield:
Add(a, d) // And not Add(a, f) because it only substitute once for each level.
e.g.
Add(a, Minus(b, c)) with replacements: Minus(b,c) -> d, b -> e, d -> f
will yield:
Add(a, f)
The mode with applyRec true can diverge if f is not well formed
Pre-transformation of the tree, with a context value from "top-down".
Pre-transformation of the tree, with a context value from "top-down".
Takes a partial function of replacements. Substitutes before recursing down the trees. The function returns an option of the new value, as well as the new context to be used for the recursion in its children. The context is "lost" when going back up, so changes made by one node will not be see by its siblings.
Pre-traversal of the tree.
Pre-traversal of the tree.
Invokes the input function on every node before visiting children. Traverse children from left to right Sources.
e.g.
Add(a, Minus(b, c))
will yield, in order:
f(Add(a, Minus(b, c))); f(a); f(Minus(b, c)); f(b); f(c)
a function to apply on each node of the expression
the expression to traverse
Replaces bottom-up sub-expressions by looking up for them in a map
A simpleTransform without a pre-transformation
A simpleTransform without a post-transformation
A genericTransform with the trivial combiner that returns ()
Generic tree traversals based on a deconstructor of a specific tree type