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

Function NewFunction

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

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

Callers 15

funcDeclFunction · 0.92
testFunctionFunction · 0.92
TestOverlappingMacroFunction · 0.92
TestCostFunction · 0.92
FunctionFunction · 0.92
buildZeroArgAsyncFunction · 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
buildZeroArgAsyncFunction · 0.74
mustNewFunctionFunction · 0.74
TestFunctionBindingsFunction · 0.56
TestFunctionMergeFunction · 0.56