MCPcopy Index your code
hub / github.com/expr-lang/expr / Function

Function Function

expr.go:152–171  ·  view source on GitHub ↗

Function adds function to list of functions what will be available in expressions.

(name string, fn func(params ...any) (any, error), types ...any)

Source from the content-addressed store, hash-verified

150
151// Function adds function to list of functions what will be available in expressions.
152func Function(name string, fn func(params ...any) (any, error), types ...any) Option {
153 return func(c *conf.Config) {
154 ts := make([]reflect.Type, len(types))
155 for i, t := range types {
156 t := reflect.TypeOf(t)
157 if t.Kind() == reflect.Ptr {
158 t = t.Elem()
159 }
160 if t.Kind() != reflect.Func {
161 panic(fmt.Sprintf("expr: type of %s is not a function", name))
162 }
163 ts[i] = t
164 }
165 c.Functions[name] = &builtin.Function{
166 Name: name,
167 Func: fn,
168 Types: ts,
169 }
170 }
171}
172
173// DisableAllBuiltins disables all builtins.
174func DisableAllBuiltins() Option {

Calls 2

ElemMethod · 0.80
SprintfMethod · 0.80

Used in the wild real call sites across dependent graphs

searching dependent graphs…