FunctionDecls provides one or more fully formed function declarations to be added to the environment.
(funcs ...*decls.FunctionDecl)
| 219 | |
| 220 | // FunctionDecls provides one or more fully formed function declarations to be added to the environment. |
| 221 | func FunctionDecls(funcs ...*decls.FunctionDecl) EnvOption { |
| 222 | return func(e *Env) (*Env, error) { |
| 223 | if len(funcs) == 0 { |
| 224 | return e, nil |
| 225 | } |
| 226 | var err error |
| 227 | e.ensureMutableFunctions() |
| 228 | for _, fn := range funcs { |
| 229 | if existing, found := e.functions[fn.Name()]; found { |
| 230 | fn, err = existing.Merge(fn) |
| 231 | if err != nil { |
| 232 | return nil, err |
| 233 | } |
| 234 | } |
| 235 | e.functions[fn.Name()] = fn |
| 236 | } |
| 237 | return e, nil |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // FunctionOpt defines a functional option for configuring a function declaration. |
| 242 | type FunctionOpt = decls.FunctionOpt |