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

Function init

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

Source from the content-addressed store, hash-verified

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