You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`quotes.reflect` contains three facilities for tree traversal and
99
99
transformation.
100
100
101
-
`TreeAccumulator` ties the knot of a traversal. By calling `foldOver(x, tree)(owner)`
102
-
we can dive into the `tree` node and start accumulating values of type `X` (e.g.,
103
-
of type `List[Symbol]` if we want to collect symbols). The code below, for
104
-
example, collects the `val` definitions in the tree.
101
+
`TreeAccumulator[X]` allows you to traverse the tree and aggregate data of type `X` along the way, by overriding its method `foldTree(x: X, tree: Tree)(owner: Symbol): X`.
102
+
103
+
`foldOverTree(x: X, tree: Tree)(owner: Symbol): X` calls `foldTree` on each children of `tree` (using `fold` to give each call the value of the previous one).
104
+
105
+
The code below, for example, collects the `val` definitions in the tree.
A `TreeTraverser` extends a `TreeAccumulator` and performs the same traversal
119
-
but without returning any value. Finally, a `TreeMap` performs a transformation.
119
+
A `TreeTraverser` extends a `TreeAccumulator[Unit]` and performs the same traversal
120
+
but without returning any value.
121
+
122
+
`TreeMap` transforms trees along the traversal, through overloading its methods it is possible to transform only trees of specific types, for example `transformStatement` only transforms `Statement`s.
123
+
120
124
121
125
#### ValDef.let
122
126
123
-
`quotes.reflect.ValDef` also offers a method `let` that allows us to bind the `rhs` (right-hand side) to a `val` and use it in `body`.
127
+
The object `quotes.reflect.ValDef` also offers a method `let` that allows us to bind the `rhs` (right-hand side) to a `val` and use it in `body`.
124
128
Additionally, `lets` binds the given `terms` to names and allows to use them in the `body`.
0 commit comments