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

Method AsFunctionOption

common/env/env.go:441–472  ·  view source on GitHub ↗

AsFunctionOption converts the serializable form of the Overload into a function declaration option.

(tp types.Provider)

Source from the content-addressed store, hash-verified

439
440// AsFunctionOption converts the serializable form of the Overload into a function declaration option.
441func (od *Overload) AsFunctionOption(tp types.Provider) (decls.FunctionOpt, error) {
442 if err := od.Validate(); err != nil {
443 return nil, err
444 }
445 args := make([]*types.Type, len(od.Args))
446 var err error
447 var errs []error
448 for i, a := range od.Args {
449 args[i], err = a.AsCELType(tp)
450 if err != nil {
451 errs = append(errs, err)
452 }
453 }
454 result, err := od.Return.AsCELType(tp)
455 if err != nil {
456 errs = append(errs, err)
457 }
458 if od.Target != nil {
459 t, err := od.Target.AsCELType(tp)
460 if err != nil {
461 errs = append(errs, err)
462 }
463 args = append([]*types.Type{t}, args...)
464 }
465 if len(errs) != 0 {
466 return nil, errors.Join(errs...)
467 }
468 if od.Target != nil {
469 return decls.MemberOverload(od.ID, args, result, decls.OverloadExamples(od.Examples...)), nil
470 }
471 return decls.Overload(od.ID, args, result, decls.OverloadExamples(od.Examples...)), nil
472}
473
474// NewExtension creates a serializable Extension from a name and version string.
475func NewExtension(name string, version uint32) *Extension {

Callers 2

AsCELFunctionMethod · 0.80

Calls 5

ValidateMethod · 0.95
MemberOverloadFunction · 0.92
OverloadExamplesFunction · 0.92
OverloadFunction · 0.92
AsCELTypeMethod · 0.80

Tested by 1