Standard library
The standard library is included by default. Call
CelEnv.NewBuilder().WithoutStandardLibrary() if you want a stripped-down
env (rare — usually for sandboxing).
Conversions
int(x) // x: int / uint / double / string / timestamp / duration / enumuint(x) // x: int / uint / double / stringdouble(x) // x: int / uint / double / stringstring(x) // x: any printablebytes(x) // x: bytes / stringtype(x) // any → typeduration(s) // s: string ('5m', '1h30m', ...)timestamp(s) // s: string (RFC 3339)dyn(x) // any → dyn (gradual typing escape hatch)Conversions throw on out-of-range or malformed input.
size
size(s) // string → int (utf8 char count)size(b) // bytes → int (byte count)size(l) // list → int (element count)size(m) // map → int (entry count)has
has(obj.field) // proto presence / has-key / has-propertyhas is a macro, not a function — it only accepts attribute selects.
See Errors & unknowns for the semantics
across object types.
String predicates
s.startsWith(prefix)s.endsWith(suffix)s.contains(sub)s.matches(regex) // regex follows RE2 syntaxFor richer string ops (replace, split, format), use the strings extension.
Comprehensions (macros)
list.all(x, p) // ∀ x ∈ list, p(x)list.exists(x, p) // ∃ x ∈ list, p(x)list.exists_one(x, p) // exactly onelist.map(x, f) // [f(x) for x in list]list.filter(x, p) // [x for x in list if p(x)]map and filter work the same on map keys (m.map(k, f)).
Two-iter forms (cel-spec macros2):
list.map(i, v, expr) // i is index, v is valuelist.filter(i, v, expr)list.all(i, v, expr)list.exists(i, v, expr)For the parser-level macro framework, see Parser macros.
Time
ts.getFullYear()ts.getMonth()ts.getDayOfMonth()ts.getDayOfWeek()ts.getHours()ts.getMinutes()ts.getSeconds()ts.getMilliseconds()ts.getDate() // alias for getDayOfMonthts.getDayOfYear()
dur.getHours()dur.getMinutes()dur.getSeconds()dur.getMilliseconds()All getters take an optional second argument: a timezone string
('America/Los_Angeles', 'UTC', '+05:30'):
ts.getHours('UTC')Arithmetic on time
timestamp - timestamp // → durationtimestamp - duration // → timestamptimestamp + duration // → timestampduration + duration // → durationduration - duration // → durationOptionals (when extension is enabled)
optional.of(x)optional.none()opt.value()opt.orValue(default)opt.hasValue()optional.ofNonZeroValue(x) // null/zero → none, else of(x)Reflection
type(x) // returns a type valuetype(x) == inttype(x) == list // unparametrised compare for parametric typesError & dynamic
dyn(x) // type at runtime; bypasses static checksSee also
- Operators — the operator-shaped built-ins.
- Macros — comprehensions and
has. - Extensions — the catalog of optional libraries.