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

Function NewStaticOptimizer

cel/optimizer.go:46–63  ·  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

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

Calls

no outgoing calls