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

Function init

common/stdlib/standard.go:40–900  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38)
39
40func init() {
41 paramA := types.NewTypeParamType("A")
42 paramB := types.NewTypeParamType("B")
43 listOfA := types.NewListType(paramA)
44 mapOfAB := types.NewMapType(paramA, paramB)
45
46 stdTypes = []*decls.VariableDecl{
47 decls.TypeVariable(types.BoolType),
48 decls.TypeVariable(types.BytesType),
49 decls.TypeVariable(types.DoubleType),
50 decls.TypeVariable(types.DurationType),
51 decls.TypeVariable(types.IntType),
52 decls.TypeVariable(listOfA),
53 decls.TypeVariable(mapOfAB),
54 decls.TypeVariable(types.NullType),
55 decls.TypeVariable(types.StringType),
56 decls.TypeVariable(types.TimestampType),
57 decls.TypeVariable(types.TypeType),
58 decls.TypeVariable(types.UintType),
59 }
60
61 stdFunctions = []*decls.FunctionDecl{
62 // Logical operators. Special-cased within the interpreter.
63 // Note, the singleton binding prevents extensions from overriding the operator behavior.
64 function(operators.Conditional,
65 decls.FunctionDocs(
66 `The ternary operator tests a boolean predicate and returns the left-hand side `+
67 `(truthy) expression if true, or the right-hand side (falsy) expression if false`),
68 decls.Overload(overloads.Conditional, argTypes(types.BoolType, paramA, paramA), paramA,
69 decls.OverloadIsNonStrict(),
70 decls.OverloadExamples(
71 `'hello'.contains('lo') ? 'hi' : 'bye' // 'hi'`,
72 `32 % 3 == 0 ? 'divisible' : 'not divisible' // 'not divisible'`)),
73 decls.SingletonFunctionBinding(noFunctionOverrides)),
74
75 function(operators.LogicalAnd,
76 decls.FunctionDocs(
77 `logically AND two boolean values. Errors and unknown values`,
78 `are valid inputs and will not halt evaluation.`),
79 decls.Overload(overloads.LogicalAnd, argTypes(types.BoolType, types.BoolType), types.BoolType,
80 decls.OverloadIsNonStrict(),
81 decls.OverloadExamples(
82 `true && true // true`,
83 `true && false // false`,
84 `error && true // error`,
85 `error && false // false`)),
86 decls.SingletonBinaryBinding(noBinaryOverrides)),
87
88 function(operators.LogicalOr,
89 decls.FunctionDocs(
90 `logically OR two boolean values. Errors and unknown values`,
91 `are valid inputs and will not halt evaluation.`),
92 decls.Overload(overloads.LogicalOr, argTypes(types.BoolType, types.BoolType), types.BoolType,
93 decls.OverloadIsNonStrict(),
94 decls.OverloadExamples(
95 `true || false // true`,
96 `false || false // false`,
97 `error || true // true`,

Callers

nothing calls this directly

Calls 15

NewTypeParamTypeFunction · 0.92
NewListTypeFunction · 0.92
NewMapTypeFunction · 0.92
TypeVariableFunction · 0.92
FunctionDocsFunction · 0.92
OverloadFunction · 0.92
OverloadIsNonStrictFunction · 0.92
OverloadExamplesFunction · 0.92
SingletonFunctionBindingFunction · 0.92
SingletonBinaryBindingFunction · 0.92
SingletonUnaryBindingFunction · 0.92
MaybeNoSuchOverloadErrFunction · 0.92

Tested by

no test coverage detected