ixfx
    Preparing search index...

    Class MapOfSimpleMutable<V>

    A simple mutable map of arrays, without events. It can store multiple values under the same key.

    For a fancier approaches, consider ofArrayMutable, ofCircularMutable or ofSetMutable.

    const m = mapOfSimpleMutable();
    m.add(`hello`, 1, 2, 3); // Adds numbers under key `hello`
    m.delete(`hello`); // Deletes everything under `hello`

    const hellos = m.get(`hello`); // Get list of items under `hello`

    Constructor takes a groupBy parameter, which yields a string key for a value. This is the basis by which values are keyed when using addValues.

    Constructor takes a valueEq parameter, which compares values. This is used when checking if a value exists under a key, for example.

    Type Parameters

    • V

      Type of items

    Hierarchy

    • MapOfSimpleBase<V>
      • MapOfSimpleMutable

    Implements

    Constructors

    • Constructor

      Type Parameters

      • V

      Parameters

      • groupBy: (value: V) => string = defaultKeyer

        Creates keys for values when using addValue. By default uses JSON.stringify

      • valueEq: IsEqual<V> = ...

        Compare values. By default uses JS logic for equality

      • initial: [string, readonly V[]][] = []

      Returns MapOfSimpleMutable<V>

    Properties

    groupBy: (value: V) => string
    map: Map<string, readonly V[]>
    valueEq: IsEqual<V>

    Accessors

    • get isEmpty(): boolean

      True if empty

      Returns boolean

    • get lengthKeys(): number

      Returns the count of keys.

      Returns number

    Methods

    • Adds several values under the same key. Duplicate values are permitted, depending on implementation.

      Parameters

      • key: string
      • ...values: readonly V[]

      Returns void

    • Adds a value, automatically extracting a key via the groupBy function assigned in the constructor options.

      Parameters

      • ...values: readonly V[]

        Adds several values

      Returns void

    • Return number of values stored under key. Returns 0 if key is not found.

      Parameters

      • key: string

      Returns number

    • Debug dump of contents

      Returns string

    • Deletes all values under key,

      Parameters

      • key: string

      Returns boolean

      True if key was found and values stored

    • Deletes value regardless of key.

      Uses the constructor-defined equality function.

      Parameters

      • value: V

        Value to delete

      Returns boolean

    • Delete value under a particular key

      Parameters

      • key: string
      • value: V

      Returns boolean

      True if value was found under key

    • Iterate over keys and array of values for that key

      Returns IterableIterator<[key: string, value: V[]]>

    • Iterate over all entries

      Returns IterableIterator<[key: string, value: V]>

    • Returns first key that contains value

      Parameters

      Returns undefined | string

    • Get all values under key

      Parameters

      • key: string

      Returns IterableIterator<V>

    • Returns true if key exists

      Parameters

      • key: string

      Returns boolean

    • Returns true if value exists under key.

      Parameters

      • key: string

        Key

      • value: V

        Value to seek under key

      Returns boolean

      True if value exists under key.

    • Iterate over all keys

      Returns IterableIterator<string>

    • Iterate over keys and length of values stored under keys

      Returns IterableIterator<[string, number]>

    • Set values to key. Previous data stored under key is thrown away.

      Parameters

      • key: string
      • values: readonly V[]

      Returns void

    • Yields the values for each key in sequence, returning an array. Use valuesFlat to iterate over all keys regardless of key.

      Returns IterableIterator<readonly V[]>

    • Iterate over all values (regardless of key). Use values to iterate over a set of values per key

      Returns IterableIterator<V>