MCPcopy Create free account
hub / github.com/cel-expr/cel-go / NewStaticOptimizer

Function NewStaticOptimizer

cel/optimizer.go:45–62  ·  view source on GitHub ↗

NewStaticOptimizer creates a StaticOptimizer with a sequence of ASTOptimizer's to be applied to a checked expression.

(options ...any)

Source from the content-addressed store, hash-verified

43// NewStaticOptimizer creates a StaticOptimizer with a sequence of ASTOptimizer's to be applied
44// to a checked expression.
45func NewStaticOptimizer(options ...any) (*StaticOptimizer, error) {
46 so := &StaticOptimizer{}
47 var err error
48 for _, opt := range options {
49 switch v := opt.(type) {
50 case ASTOptimizer:
51 so.optimizers = append(so.optimizers, v)
52 case OptimizerOption:
53 so, err = v(so)
54 if err != nil {
55 return nil, err
56 }
57 default:
58 return nil, fmt.Errorf("unsupported option: %v", v)
59 }
60 }
61 return so, nil
62}
63
64// OptimizeWithSource overrides the source used by the optimizer.
65// Note this will cause the source info from the AST passed to Optimize() to be discarded.

Calls

no outgoing calls