본문으로 건너뛰기
토파즈문서
6.05.21

문서 검색

명세 6.0

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

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

    다운로드

    라이브러리 · 컬렉션

    Map.length

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

    Map<R0, R1>.length: int
    수신자
    Map
    최소 인자 수
    0
    최대 인자 수
    0
    언어 모드
    6.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

    매개변수 제약

    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.

    Test collection emptiness with length

    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
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 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
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 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
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 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
    기대 결과

    기대 결과

    거절 단계 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
    기대 결과

    기대 결과

    거절 단계 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
    기대 결과

    기대 결과

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

    Diagnostics

    Unknown member or field →