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