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

Method CompileOptions

ext/lists.go:276–490  ·  view source on GitHub ↗

CompileOptions implements the Library interface method.

()

Source from the content-addressed store, hash-verified

274
275// CompileOptions implements the Library interface method.
276func (lib listsLib) CompileOptions() []cel.EnvOption {
277 listType := cel.ListType(cel.TypeParamType("T"))
278 listListType := cel.ListType(listType)
279 listDyn := cel.ListType(cel.DynType)
280 var adapt func() types.Adapter
281 captureAdapt := func(e *cel.Env) (*cel.Env, error) {
282 adapt = e.CELTypeAdapter
283 return e, nil
284 }
285 opts := []cel.EnvOption{
286 captureAdapt,
287 cel.Function("slice",
288 cel.MemberOverload("list_slice",
289 []*cel.Type{listType, cel.IntType, cel.IntType}, listType,
290 cel.FunctionBinding(func(args ...ref.Val) ref.Val {
291 list := args[0].(traits.Lister)
292 start := args[1].(types.Int)
293 end := args[2].(types.Int)
294 result, err := slice(adapt(), list, start, end)
295 if err != nil {
296 return types.WrapErr(err)
297 }
298 return result
299 }),
300 ),
301 ),
302 }
303 if lib.version >= 1 {
304 opts = append(opts,
305 cel.Function("flatten",
306 cel.MemberOverload("list_flatten",
307 []*cel.Type{listListType}, listType,
308 cel.UnaryBinding(func(arg ref.Val) ref.Val {
309 // double-check as type-guards disabled
310 list, ok := arg.(traits.Lister)
311 if !ok {
312 return types.ValOrErr(arg, "no such overload: %v.flatten()", arg.Type())
313 }
314 flatList, err := flatten(list, 1)
315 if err != nil {
316 return types.WrapErr(err)
317 }
318
319 return adapt().NativeToValue(flatList)
320 }),
321 ),
322 cel.MemberOverload("list_flatten_int",
323 []*cel.Type{listDyn, types.IntType}, listDyn,
324 cel.BinaryBinding(func(arg1, arg2 ref.Val) ref.Val {
325 // double-check as type-guards disabled
326 list, ok := arg1.(traits.Lister)
327 if !ok {
328 return types.ValOrErr(arg1, "no such overload: %v.flatten(%v)", arg1.Type(), arg2.Type())
329 }
330 depth, ok := arg2.(types.Int)
331 if !ok {
332 return types.ValOrErr(arg1, "no such overload: %v.flatten(%v)", arg1.Type(), arg2.Type())
333 }

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