gradum-kit - v0.1.0
    Preparing search index...

    Class GradumMap<KeyType, ValueType>

    GradumMap

    A Map that hands out copies instead of references, so callers cannot mutate stored values by accident. It also adds array accessors and the usual map/filter/merge helpers, which return new maps rather than mutating this one. Set enforceImmutability to false to get plain reference semantics back.

    Type Parameters

    • KeyType

      The type of the keys.

    • ValueType

      The type of the stored values.

    Hierarchy

    Index
    enforceImmutability: boolean = true

    Whether values are copied on the way in and out. While true (the default), stored objects are cloned, so mutating a value you read back does not affect the map. Set it to false to store and return the original references.

    • get first(): ValueType

      Returns ValueType

      The first value in insertion order, or null when the map is empty. Copied unless enforceImmutability is false.

    • get last(): ValueType

      Returns ValueType

      The last value in insertion order, or null when the map is empty. Copied unless enforceImmutability is false.

    • Parameters

      Returns any

      Itself, allowing for method chaining.

      Store a value at the given key. The value is copied first unless enforceImmutability is false.

    • Parameters

      Returns ValueType

      A copy of the stored value, or the value itself when enforceImmutability is false. undefined if the key is not set.

      Read the value at the given key.

    • Returns KeyType[]

      A new array of the map's keys.

      All keys as an array, in insertion order.

    • Returns ValueType[]

      A new array of the map's values. The values themselves are not copied.

      All values as an array, in insertion order.

    • Type Parameters

      • C

        The type of the new keys.

      Parameters

      • callback: (key: KeyType, value: ValueType) => C

        Returns the new key for each entry.

      Returns GradumMap<C, ValueType>

      A new map. This map is left unchanged. Entries whose callback returns the same key collapse into one.

      Derive a new map with the same values under recomputed keys.

    • Type Parameters

      • C

        The type of the new values.

      Parameters

      • callback: (key: KeyType, value: ValueType) => C

        Returns the new value for each entry.

      Returns GradumMap<KeyType, C>

      A new map. This map is left unchanged.

      Derive a new map with the same keys and recomputed values.