]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | package terraform |
2 | ||
3 | // EvalNodeFilterFunc is the callback used to replace a node with | |
4 | // another to node. To not do the replacement, just return the input node. | |
5 | type EvalNodeFilterFunc func(EvalNode) EvalNode | |
6 | ||
7 | // EvalNodeFilterable is an interface that can be implemented by | |
8 | // EvalNodes to allow filtering of sub-elements. Note that this isn't | |
9 | // a common thing to implement and you probably don't need it. | |
10 | type EvalNodeFilterable interface { | |
11 | EvalNode | |
12 | Filter(EvalNodeFilterFunc) | |
13 | } | |
14 | ||
15 | // EvalFilter runs the filter on the given node and returns the | |
16 | // final filtered value. This should be called rather than checking | |
17 | // the EvalNode directly since this will properly handle EvalNodeFilterables. | |
18 | func EvalFilter(node EvalNode, fn EvalNodeFilterFunc) EvalNode { | |
19 | if f, ok := node.(EvalNodeFilterable); ok { | |
20 | f.Filter(fn) | |
21 | return node | |
22 | } | |
23 | ||
24 | return fn(node) | |
25 | } |