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

Function SingletonFunctionBinding

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

560// Note, this approach works well if operand is expected to have a specific trait which it implements,
561// e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.
562func SingletonFunctionBinding(fn functions.FunctionOp, traits ...int) FunctionOpt {
563 trait := 0
564 for _, t := range traits {
565 trait = trait | t
566 }
567 return func(f *FunctionDecl) (*FunctionDecl, error) {
568 if f.singleton != nil {
569 return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name())
570 }
571 f.singleton = &functions.Overload{
572 Operator: f.Name(),
573 Function: fn,
574 OperandTrait: trait,
575 }
576 return f, nil
577 }
578}
579
580// SingletonAsyncBinding creates a singleton async function definition to be used with all function overloads.
581// The provided function is called in its own goroutine with the provided context. The function should

Callers 6

testDataFunction · 0.92
SingletonFunctionImplFunction · 0.92
SingletonFunctionBindingFunction · 0.92
initStandardFunction · 0.92

Calls 1

NameMethod · 0.65