NewFunctionActivation returns an Activation which supplies implementations for late-bound functions in addition to the variables provided by the `vars` input. The `vars` value may either be an Activation or any valid input to the NewActivation call, and the result is the same kind of activation tha
(vars any, funcs map[string]functions.LateBoundOp)
| 289 | // so an error is returned when `vars` already supplies function bindings. Supply the complete set |
| 290 | // of bindings in a single call instead of layering them. |
| 291 | func NewFunctionActivation(vars any, funcs map[string]functions.LateBoundOp) (FunctionActivation, error) { |
| 292 | // Copy the input to ensure the bindings observed during an evaluation cannot be mutated by |
| 293 | // the caller once the activation has been created. |
| 294 | bindings := make(map[string]functions.LateBoundOp, len(funcs)) |
| 295 | for name, fn := range funcs { |
| 296 | if fn == nil { |
| 297 | return nil, fmt.Errorf("function binding must be non-nil: %s", name) |
| 298 | } |
| 299 | bindings[name] = fn |
| 300 | } |
| 301 | if m, isMap := vars.(map[string]any); isMap { |
| 302 | return &mapActivation{bindings: m, functions: bindings}, nil |
| 303 | } |
| 304 | a, err := NewActivation(vars) |
| 305 | if err != nil { |
| 306 | return nil, err |
| 307 | } |
| 308 | if err := checkNoFunctionActivation(a); err != nil { |
| 309 | return nil, err |
| 310 | } |
| 311 | return &mapActivation{functions: bindings, parent: a}, nil |
| 312 | } |
| 313 | |
| 314 | // errNestedFunctionActivation reports a hierarchy which supplies late-bound functions from more |
| 315 | // than one activation, where the bindings which apply would depend on the order in which the |