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

Method CompileOptions

ext/lists.go:205–388  ·  view source on GitHub ↗

CompileOptions implements the Library interface method.

()

Source from the content-addressed store, hash-verified

203
204// CompileOptions implements the Library interface method.
205func (lib listsLib) CompileOptions() []cel.EnvOption {
206 listType := cel.ListType(cel.TypeParamType("T"))
207 listListType := cel.ListType(listType)
208 listDyn := cel.ListType(cel.DynType)
209 opts := []cel.EnvOption{
210 cel.Function("slice",
211 cel.MemberOverload("list_slice",
212 []*cel.Type{listType, cel.IntType, cel.IntType}, listType,
213 cel.FunctionBinding(func(args ...ref.Val) ref.Val {
214 list := args[0].(traits.Lister)
215 start := args[1].(types.Int)
216 end := args[2].(types.Int)
217 result, err := slice(list, start, end)
218 if err != nil {
219 return types.WrapErr(err)
220 }
221 return result
222 }),
223 ),
224 ),
225 }
226 if lib.version >= 1 {
227 opts = append(opts,
228 cel.Function("flatten",
229 cel.MemberOverload("list_flatten",
230 []*cel.Type{listListType}, listType,
231 cel.UnaryBinding(func(arg ref.Val) ref.Val {
232 // double-check as type-guards disabled
233 list, ok := arg.(traits.Lister)
234 if !ok {
235 return types.ValOrErr(arg, "no such overload: %v.flatten()", arg.Type())
236 }
237 flatList, err := flatten(list, 1)
238 if err != nil {
239 return types.WrapErr(err)
240 }
241
242 return types.DefaultTypeAdapter.NativeToValue(flatList)
243 }),
244 ),
245 cel.MemberOverload("list_flatten_int",
246 []*cel.Type{listDyn, types.IntType}, listDyn,
247 cel.BinaryBinding(func(arg1, arg2 ref.Val) ref.Val {
248 // double-check as type-guards disabled
249 list, ok := arg1.(traits.Lister)
250 if !ok {
251 return types.ValOrErr(arg1, "no such overload: %v.flatten(%v)", arg1.Type(), arg2.Type())
252 }
253 depth, ok := arg2.(types.Int)
254 if !ok {
255 return types.ValOrErr(arg1, "no such overload: %v.flatten(%v)", arg1.Type(), arg2.Type())
256 }
257 flatList, err := flatten(list, int64(depth))
258 if err != nil {
259 return types.WrapErr(err)
260 }
261
262 return types.DefaultTypeAdapter.NativeToValue(flatList)

Callers

nothing calls this directly

Calls 15

FunctionFunction · 0.92
MemberOverloadFunction · 0.92
FunctionBindingFunction · 0.92
WrapErrFunction · 0.92
UnaryBindingFunction · 0.92
ValOrErrFunction · 0.92
BinaryBindingFunction · 0.92
DisableTypeGuardsFunction · 0.92
SingletonUnaryBindingFunction · 0.92
MacrosFunction · 0.92
ReceiverMacroFunction · 0.92
SingletonBinaryBindingFunction · 0.92

Tested by

no test coverage detected