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

Function NewFunction

common/decls/decls.go:36–53  ·  view source on GitHub ↗

NewFunction creates a new function declaration with a set of function options to configure overloads and function definitions (implementations). Functions are checked for name collisions and singleton redefinition.

(name string, opts ...FunctionOpt)

Source from the content-addressed store, hash-verified

34//
35// Functions are checked for name collisions and singleton redefinition.
36func NewFunction(name string, opts ...FunctionOpt) (*FunctionDecl, error) {
37 fn := &FunctionDecl{
38 name: name,
39 overloads: map[string]*OverloadDecl{},
40 overloadOrdinals: []string{},
41 }
42 var err error
43 for _, opt := range opts {
44 fn, err = opt(fn)
45 if err != nil {
46 return nil, err
47 }
48 }
49 if len(fn.overloads) == 0 {
50 return nil, fmt.Errorf("function %s must have at least one overload", name)
51 }
52 return fn, nil
53}
54
55// FunctionDecl defines a function name, overload set, and optionally a singleton definition for all
56// overload instances.

Callers 15

funcDeclFunction · 0.92
testFunctionFunction · 0.92
TestOverlappingMacroFunction · 0.92
TestCostFunction · 0.92
FunctionFunction · 0.92
functionFunction · 0.92
AsCELFunctionMethod · 0.92
mustNewFunctionFunction · 0.92
TestFunctionBindingsFunction · 0.70

Calls

no outgoing calls

Tested by 15

funcDeclFunction · 0.74
testFunctionFunction · 0.74
TestOverlappingMacroFunction · 0.74
TestCostFunction · 0.74
mustNewFunctionFunction · 0.74
TestFunctionBindingsFunction · 0.56
TestFunctionMergeFunction · 0.56