MCPcopy
hub / github.com/hashicorp/hcl / UnwrapExpressionUntil

Function UnwrapExpressionUntil

expr_unwrap.go:57–71  ·  view source on GitHub ↗

UnwrapExpressionUntil is similar to UnwrapExpression except it gives the caller an opportunity to test each level of unwrapping to see each a particular expression is accepted. This could be used, for example, to unwrap until a particular other interface is satisfied, regardless of wrap wrapping le

(expr Expression, until func(Expression) bool)

Source from the content-addressed store, hash-verified

55// function rejects even the final, physical expression then the result of
56// this function is nil.
57func UnwrapExpressionUntil(expr Expression, until func(Expression) bool) Expression {
58 for {
59 if until(expr) {
60 return expr
61 }
62 unwrap, wrapped := expr.(unwrapExpression)
63 if !wrapped {
64 return nil
65 }
66 expr = unwrap.UnwrapExpression()
67 if expr == nil {
68 return nil
69 }
70 }
71}

Callers 5

AbsTraversalForExprFunction · 0.85
ExprAsKeywordFunction · 0.85
ExprListFunction · 0.85
ExprMapFunction · 0.85
ExprCallFunction · 0.85

Calls 1

UnwrapExpressionMethod · 0.65

Tested by

no test coverage detected