len() Builtin
The len() builtin returns the length of arrays, maps, and strings.
- Signature:
len(value any) -> int - Supported types: arrays, maps, strings
- Strict behavior: calling
len(None)orlen()with unsupported types raises a runtime error.
Quick examples
| Quick Examples | |
|---|---|
Strict error behavior
The builtin performs strict type checking. If called with None or any unsupported type, it raises a runtime error.
| len() Examples | |
|---|---|
Common unsupported arguments: - Integers, floats, booleans - Structs without a string representation as a sequence - None (strictly rejected)
Practical patterns
-
Array bounds and iteration:
-
Map size checks:
-
String processing:
String Processing
Notes
- Behavior mirrors the language’s strict runtime type validation. Use explicit conditionals to check for
Nonebefore callinglenwhen inputs may be missing.