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

Function SingletonFunctionBinding

common/decls/decls.go:523–539  ·  view source on GitHub ↗

SingletonFunctionBinding creates a singleton function definition to be used with all function overloads. Note, this approach works well if operand is expected to have a specific trait which it implements, e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.

(fn functions.FunctionOp, traits ...int)

Source from the content-addressed store, hash-verified

521// Note, this approach works well if operand is expected to have a specific trait which it implements,
522// e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.
523func SingletonFunctionBinding(fn functions.FunctionOp, traits ...int) FunctionOpt {
524 trait := 0
525 for _, t := range traits {
526 trait = trait | t
527 }
528 return func(f *FunctionDecl) (*FunctionDecl, error) {
529 if f.singleton != nil {
530 return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name())
531 }
532 f.singleton = &functions.Overload{
533 Operator: f.Name(),
534 Function: fn,
535 OperandTrait: trait,
536 }
537 return f, nil
538 }
539}
540
541// Overload defines a new global overload with an overload id, argument types, and result type. Through the
542// use of OverloadOpt options, the overload may also be configured with a binding, an operand trait, and to

Callers 6

testDataFunction · 0.92
SingletonFunctionImplFunction · 0.92
SingletonFunctionBindingFunction · 0.92
initFunction · 0.92

Calls 1

NameMethod · 0.65