본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    라이브러리 · 컬렉션

    Map.length for K, V

    Inspect the declaration, parameters, and availability of this API.

    length: int
    수신자
    Map<K, V>
    최소 인자 수
    0
    최대 인자 수
    0

    Declaration and parameters

    링크

    사용 조건

    기본 포함 · 예

    These types are provided by the language. No module import is required.

    The declarations below describe the standard operations on built-in values.

    수신자

    Map<K, V>

    매개변수 제약

    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.

    결과

    The declared result type is int.

    효과

    실패

    Result and effects

    링크

    Select 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

    링크

    Collections →

    Test collection emptiness with length

    링크
    규칙topaz.stdlib.contract.collection-emptiness.rule

    Test 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.

    이유

    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.

    Test empty and nonempty maps with length

    링크
    main.tpzTest empty and nonempty maps with length플레이그라운드 열기 →
    1. import std.io
    2. let empty: Map<string, int> = map {}
    3. let filled = map { "one": 1 }
    4. io.writeLine("{empty.length == 0}:{filled.length == 0}")
    기대 출력종료 코드 0
    true:false
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. true:false

    Test empty and nonempty sets with length

    링크
    main.tpzTest empty and nonempty sets with length플레이그라운드 열기 →
    1. import std.io
    2. let empty: Set<int> = set {}
    3. let filled = set { 1 }
    4. io.writeLine("{empty.length == 0}:{filled.length == 0}")
    기대 출력종료 코드 0
    true:false
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. true:false

    Test empty and nonempty byte sequences with length

    링크
    main.tpzTest empty and nonempty byte sequences with length플레이그라운드 열기 →
    1. import std.bytes { Bytes }
    2. import std.test
    3. import std.io
    4. let empty = Bytes.empty()
    5. let filled = test.assertOk(Bytes.fromArray([1]))
    6. io.writeLine("{empty.length == 0}:{filled.length == 0}")
    기대 출력종료 코드 0
    true:false
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. true:false

    Reject Bytes.isEmpty

    링크
    main.tpzReject Bytes.isEmpty플레이그라운드 열기 →
    1. import std.bytes { Bytes }
    2. function inspect(value: Bytes) -> () {
    3. let result = value.isEmpty()
    4. return ()
    5. }
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check main.tpz --format json · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    Reject Map.isEmpty

    링크
    main.tpzReject Map.isEmpty플레이그라운드 열기 →
    1. function inspect(value: Map<string, int>) -> () {
    2. let result = value.isEmpty()
    3. return ()
    4. }
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check main.tpz --format json · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    Reject Set.isEmpty

    링크
    main.tpzReject Set.isEmpty플레이그라운드 열기 →
    1. function inspect(value: Set<int>) -> () {
    2. let result = value.isEmpty()
    3. return ()
    4. }
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check main.tpz --format json · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    Diagnostics

    링크

    Unknown member or field →

    메뉴

    다운로드 →