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

Function SingletonBinaryBinding

common/decls/decls.go:540–556  ·  view source on GitHub ↗

SingletonBinaryBinding 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.BinaryOp, traits ...int)

Source from the content-addressed store, hash-verified

538// Note, this approach works well if operand is expected to have a specific trait which it implements,
539// e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.
540func SingletonBinaryBinding(fn functions.BinaryOp, traits ...int) FunctionOpt {
541 trait := 0
542 for _, t := range traits {
543 trait = trait | t
544 }
545 return func(f *FunctionDecl) (*FunctionDecl, error) {
546 if f.singleton != nil {
547 return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name())
548 }
549 f.singleton = &functions.Overload{
550 Operator: f.Name(),
551 Binary: fn,
552 OperandTrait: trait,
553 }
554 return f, nil
555 }
556}
557
558// SingletonFunctionBinding creates a singleton function definition to be used with all function overloads.
559//

Callers 5

SingletonBinaryImplFunction · 0.92
SingletonBinaryBindingFunction · 0.92
initStandardFunction · 0.92
TestFunctionNoOverloadsFunction · 0.70

Calls 1

NameMethod · 0.65

Tested by 2

TestFunctionNoOverloadsFunction · 0.56