@lang:len
Length of a value: element count for an array, byte length for a string or bytes.
Returns: number
Syntax
Section titled “Syntax”@lang:len(value)Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
value | array | Source array, string or bytes value |
See Also
Section titled “See Also”On-chain face (@len!)
Section titled “On-chain face (@len!)”The element count of a literal, live fixed-size or dynamic array, or nested collection helper. For a call returning string/bytes, return its decoded byte length.
Examples
Section titled “Examples”load lang
set $gov 0xc0dbDcA66a0636236fAbe1B3C16B1bD4C84bB1E1
# Top level: compiles to a core nav ending in the LEN sentinelassert @len!($gov::!{voters()(address[])}) >= 3 "not enough voters"assert @len!($gov::!{voters()(address[])}) != 0
# Nested: the same LEN-sentinel nav, composable as a numberassert @calc!(@len!($gov::!{voters()(address[])}) * 2) > 4- For a string/bytes return the decoded length is the byte length (UTF-8
characters may span multiple bytes). For raw returndata size use
@bytes.len!. - Over a nested collection helper (
@len!(@filter!(…)),@len!(@safe:owners!())) the length is the live element count. Pairs count as one element. Generic pipelines can return their count without first packing the final array; byte lengths of string/bytes helpers stay with@bytes.len!/@str.len!.
See Also
Section titled “See Also”assert,@bytes.len!
Return-value lenses can select whole fixed arrays, including inside tuples and other arrays. The full selected value must be present; a truncated return reverts even when its declared fixed length is known at compile time.