Skip to content
FutureBlitz

    Install

    Import std.collections.immutable

    ImmutableMap

    std.collections.immutable

    struct

    @DebugEntries Public Struct ImmutableMap<K, V> Implements Iterable<(K, V)>, Defaultable, Sendable

    A Map that never changes: each change gives a new one, which shares what it can with the old, so threads can share it.

    Examples

    Local empty = ImmutableMap<String, Int>()
    Local ages = empty.Add("Ada", 36).Add("Alan", 41)
    Expect(empty.Count == 0 && ages.Count == 2)
    Expect(ages.Get("Ada") == 36)
    Expect(!ages.Remove("Ada").Contains("Ada") && ages.Contains("Ada"))

    std/collections/immutable.fb, line 372

    • Public New() constructor #

      An empty one.

    • Public Static Method From(entries: Iterable<(K, V)>): ImmutableMap<K, V> static method #

      One with the entries, all read first, a second entry's value for a key taking the place of an earlier one's.

    • Public Property Count: Int property #

      How many entries it holds.

    • Public Method Get(key: K): V? method #

      The key's value, or Null when it isn't there.

    • Public Method Get(key: K, fallback: V): V method #

      The key's value, or fallback when it isn't there.

    • @PanicsAtCaller Operator [](key: K): V operator #

      The key's value. A key that isn't there panics.

    • Public Method Contains(key: K): Bool method #

      Whether key has an entry.

    • Public Method Add(key: K, value: V): ImmutableMap<K, V> method #

      A copy with the key's value, which takes the place of the one it has.

    • Public Method AddAll(entries: Iterable<(K, V)>): ImmutableMap<K, V> method #

      A copy with each of the entries added in turn, as Add adds one, all read first.

    • Public Method Remove(key: K): ImmutableMap<K, V> method #

      A copy without the key's entry, or the same one when it has none.

    • Public Method Keys(): K[] method #

      The keys, in the order the entries go in.

    • Public Method Values(): V[] method #

      The values, in their keys' order.

    • Public Method ToMap(): Map<K, V> method #

      A new Map with the same entries, in the same order.

    • Public Static Method DefaultValue(): ImmutableMap<K, V> static method #

      An empty one.

    • Public Method Iterate(): ImmutableMapIterator<K, V> method #

      Each key and its value, for 'For key, value In map', by their keys' hashes, and keys of one hash in the order they were added.

    Report an issue with this page or with FutureBlitz on GitHub.