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

Function SingletonUnaryBinding

common/decls/decls.go:497–513  ·  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

495// Note, this approach works well if operand is expected to have a specific trait which it implements,
496// e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.
497func SingletonUnaryBinding(fn functions.UnaryOp, traits ...int) FunctionOpt {
498 trait := 0
499 for _, t := range traits {
500 trait = trait | t
501 }
502 return func(f *FunctionDecl) (*FunctionDecl, error) {
503 if f.singleton != nil {
504 return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name())
505 }
506 f.singleton = &functions.Overload{
507 Operator: f.Name(),
508 Unary: fn,
509 OperandTrait: trait,
510 }
511 return f, nil
512 }
513}
514
515// SingletonBinaryBinding creates a singleton function definition to be used with all function overloads.
516//

Callers 9

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

Calls 1

NameMethod · 0.65