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

Function SingletonUnaryBinding

common/decls/decls.go:479–495  ·  view source on GitHub ↗

SingletonUnaryBinding creates a singleton function definition to be used for 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.UnaryOp, traits ...int)

Source from the content-addressed store, hash-verified

477// Note, this approach works well if operand is expected to have a specific trait which it implements,
478// e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.
479func SingletonUnaryBinding(fn functions.UnaryOp, traits ...int) FunctionOpt {
480 trait := 0
481 for _, t := range traits {
482 trait = trait | t
483 }
484 return func(f *FunctionDecl) (*FunctionDecl, error) {
485 if f.singleton != nil {
486 return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name())
487 }
488 f.singleton = &functions.Overload{
489 Operator: f.Name(),
490 Unary: fn,
491 OperandTrait: trait,
492 }
493 return f, nil
494 }
495}
496
497// SingletonBinaryBinding creates a singleton function definition to be used with all function overloads.
498//

Callers 9

testDataFunction · 0.92
SingletonUnaryBindingFunction · 0.92
initFunction · 0.92
TestFunctionMergeFunction · 0.70

Calls 1

NameMethod · 0.65