length: int- Module
- Collections
- Receiver
- Set<T>
- Minimum arity
- 0
- Maximum arity
- 0
Declaration and parameters
LinkAvailability
Included by default: yes
These types are provided by the language. No module import is required.
The declarations below describe the standard operations on built-in values.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858
Receiver
Set<T>
Parameter constraints
Test whether a Bytes, Map, or Set value is empty by comparing its length property with zero. The comparison is true exactly when the collection has no bytes, entries, or elements.
Bytes, Map, and Set do not expose an isEmpty member. Read the length property and use the ordinary equality operator.
Related rule: Test collection emptiness with lengthResult
The declared result type is int.
Effects
Failures
Result and effects
LinkSelect this field from a value of its named type without call parentheses.
Runtime behavior, boundary inputs, effects, and failures remain Pending until their source contracts and public CLI observations are reviewed.
Related entries
LinkTest collection emptiness with length
LinkTest collection emptiness with length
Test whether a Bytes, Map, or Set value is empty by comparing its length property with zero. The comparison is true exactly when the collection has no bytes, entries, or elements.
Bytes, Map, and Set do not expose an isEmpty member. Read the length property and use the ordinary equality operator.
Why
A collection already exposes its count through length. Comparing that value with zero expresses emptiness for every collection without another query name or a type-specific method.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Test empty and nonempty maps with length
Linkimport std.iolet empty: Map<string, int> = map {}let filled = map { "one": 1 }io.writeLine("{empty.length == 0}:{filled.length == 0}")
true:false
Expected result
Expected result
Execution completes. Exit code 0.
true:false
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Test empty and nonempty sets with length
Linkimport std.iolet empty: Set<int> = set {}let filled = set { 1 }io.writeLine("{empty.length == 0}:{filled.length == 0}")
true:false
Expected result
Expected result
Execution completes. Exit code 0.
true:false
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Test empty and nonempty byte sequences with length
Linkimport std.bytes { Bytes }import std.testimport std.iolet empty = Bytes.empty()let filled = test.assertOk(Bytes.fromArray([1]))io.writeLine("{empty.length == 0}:{filled.length == 0}")
true:false
Expected result
Expected result
Execution completes. Exit code 0.
true:false
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Reject Bytes.isEmpty
Linkimport std.bytes { Bytes }function inspect(value: Bytes) -> () {let result = value.isEmpty()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Reject Map.isEmpty
Linkfunction inspect(value: Map<string, int>) -> () {let result = value.isEmpty()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Reject Set.isEmpty
Linkfunction inspect(value: Set<int>) -> () {let result = value.isEmpty()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi