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

Method CompileOptions

cel/library.go:413–593  ·  view source on GitHub ↗

CompileOptions implements the Library interface method.

()

Source from the content-addressed store, hash-verified

411
412// CompileOptions implements the Library interface method.
413func (lib *optionalLib) CompileOptions() []EnvOption {
414 paramTypeK := TypeParamType("K")
415 paramTypeV := TypeParamType("V")
416 optionalTypeV := OptionalType(paramTypeV)
417 listTypeV := ListType(paramTypeV)
418 mapTypeKV := MapType(paramTypeK, paramTypeV)
419 listOptionalTypeV := ListType(optionalTypeV)
420
421 opts := []EnvOption{
422 // Enable the optional syntax in the parser.
423 enableOptionalSyntax(),
424
425 // Introduce the optional type.
426 Types(types.OptionalType),
427
428 // Configure the optMap and optFlatMap macros.
429 Macros(ReceiverMacro(optMapMacro, 2, optMap,
430 MacroDocs(`perform computation on the value if present and return the result as an optional`),
431 MacroExamples(
432 common.MultilineDescription(
433 `// sub with the prefix 'dev.cel' or optional.none()`,
434 `request.auth.tokens.?sub.optMap(id, 'dev.cel.' + id)`),
435 `optional.none().optMap(i, i * 2) // optional.none()`))),
436
437 // Global and member functions for working with optional values.
438 Function(optionalOfFunc,
439 FunctionDocs(`create a new optional_type(T) with a value where any value is considered valid`),
440 Overload("optional_of", []*Type{paramTypeV}, optionalTypeV,
441 OverloadExamples(`optional.of(1) // optional(1)`),
442 UnaryBinding(func(value ref.Val) ref.Val {
443 return types.OptionalOf(value)
444 }))),
445 Function(optionalOfNonZeroValueFunc,
446 FunctionDocs(`create a new optional_type(T) with a value, if the value is not a zero or empty value`),
447 Overload("optional_ofNonZeroValue", []*Type{paramTypeV}, optionalTypeV,
448 OverloadExamples(
449 `optional.ofNonZeroValue(null) // optional.none()`,
450 `optional.ofNonZeroValue("") // optional.none()`,
451 `optional.ofNonZeroValue("hello") // optional.of('hello')`),
452 UnaryBinding(func(value ref.Val) ref.Val {
453 v, isZeroer := value.(traits.Zeroer)
454 if !isZeroer || !v.IsZeroValue() {
455 return types.OptionalOf(value)
456 }
457 return types.OptionalNone
458 }))),
459 Function(optionalNoneFunc,
460 FunctionDocs(`singleton value representing an optional without a value`),
461 Overload("optional_none", []*Type{}, optionalTypeV,
462 OverloadExamples(`optional.none()`),
463 FunctionBinding(func(values ...ref.Val) ref.Val {
464 return types.OptionalNone
465 }))),
466 Function(valueFunc,
467 FunctionDocs(`obtain the value contained by the optional, error if optional.none()`),
468 MemberOverload("optional_value", []*Type{optionalTypeV}, paramTypeV,
469 OverloadExamples(
470 `optional.of(1).value() // 1`,

Callers

nothing calls this directly

Calls 15

MultilineDescriptionFunction · 0.92
OptionalOfFunction · 0.92
BoolTypeAlias · 0.92
IntTypeAlias · 0.92
enableOptionalSyntaxFunction · 0.85
ReceiverMacroFunction · 0.85
GetValueMethod · 0.80
HasValueMethod · 0.80
TypesFunction · 0.70
MacrosFunction · 0.70
MacroDocsFunction · 0.70
MacroExamplesFunction · 0.70

Tested by

no test coverage detected