Class Collection<K, V>

Represents a class to hold key-value pairs using Collection. This is a extension of [Map] to add Array-like functions and a update builder.

Type Parameters

Hierarchy

Constructors

  • Type Parameters

    • K

    • V = unknown

    Parameters

    • Optional entries: null | readonly (readonly [K, V])[]

    Returns Collection<K, V>

  • Type Parameters

    • K

    • V = unknown

    Parameters

    • Optional iterable: null | Iterable<readonly [K, V]>

    Returns Collection<K, V>

Properties

[toStringTag]: string
constructor: typeof Collection
size: number
[species]: MapConstructor

Accessors

  • get empty(): boolean
  • Returns if this [[Collection]] is empty or not

    Returns boolean

Methods

  • Returns an iterable of entries in the map.

    Returns IterableIterator<[K, V]>

  • Returns void

  • Parameters

    • key: K

    Returns boolean

  • Computes a value if it's absent in this Collection

    Parameters

    • key: K

      The key to find

    • insert: V | (() => V)

      Item to add when it doesn't exist

    Returns V

  • Returns an iterable of key, value pairs for every entry in the map.

    Returns IterableIterator<[K, V]>

  • Use a predicate function to filter out anything and return a new Array

    Returns

    A new Array of the values that returned true in the predicate function

    Type Parameters

    Parameters

    • predicate: Predicate<ThisArg, V, number, K, boolean>

      The predicate function to filter out

    • Optional thisArg: ThisArg

      An additional this context if needed

    Returns V[]

  • Use a predicate function to filter out keys and return a new Array of the keys that resolved true in the predicate function. Use Collection#filter to filter out any values from this [[Collection]].

    Returns

    A new Array of the values that returned true in the predicate function

    Type Parameters

    Parameters

    • predicate: Predicate<ThisArg, V, number, K, boolean>

      The predicate function to filter out

    • Optional thisArg: ThisArg

      An additional this context if needed

    Returns K[]

  • Find a value in the collection from it's predicate function

    Returns

    The value found or null if not found

    Type Parameters

    Parameters

    • predicate: Predicate<ThisArg, V, number, K, boolean>

      The predicate function

    • Optional thisArg: ThisArg

      An additional this context if needed

    Returns null | V

  • Finds a key in the collection from it's predicate function

    Returns

    The key found or null if not found

    Type Parameters

    Parameters

    • predicate: MinimalPredicate<ThisArg, V, boolean>

      The predicate function

    • Optional thisArg: ThisArg

      An additional this context if needed

    Returns null | K

  • Returns the first element in the collection

    Returns undefined | V

  • Returns an Array of the values from the correspondant amount

    Parameters

    • amount: number

      The amount to fetch from

    Returns V[]

  • Returns the first key in the collection

    Returns undefined | K

  • Returns an Array of the keys from the correspondant amount

    Parameters

    • amount: number

      The amount to fetch from

    Returns K[]

  • Parameters

    • callbackfn: ((value: V, key: K, map: Map<K, V>) => void)
        • (value: V, key: K, map: Map<K, V>): void
        • Parameters

          • value: V
          • key: K
          • map: Map<K, V>

          Returns void

    • Optional thisArg: any

    Returns void

  • Parameters

    • key: K

    Returns undefined | V

  • Parameters

    • key: K

    Returns boolean

  • Returns an iterable of keys in the map

    Returns IterableIterator<K>

  • Returns the last element in the collection

    Returns undefined | V

  • Returns an Array of the values from the correspondant amount

    Parameters

    • amount: number

      The amount to fetch from

    Returns V[]

  • Returns the last element in the collection

    Returns undefined | K

  • Returns an Array of the values from the correspondant amount

    Parameters

    • amount: number

      The amount to fetch from

    Returns K[]

  • Use a predicate function to map anything into a new array

    Returns

    A new Array of the values from that function

    Type Parameters

    Parameters

    • predicate: Predicate<ThisArg, V, number, K, S>

      The predicate function to map out and return a new array

    • Optional thisArg: ThisArg

      An additional this context if needed

    Returns S[]

  • Returns a random value from the collection

    Returns

    A random value or null if the collection is empty

    Returns null | V

  • Reduce the collection and return a new initial value

    Type Parameters

    • S

    Parameters

    • predicate: ReducePredicate<Collection<K, V>, V, S, S>

      The predicate function

    • Optional initialValue: S

      The initial value

    Returns S

  • Parameters

    • key: K
    • value: V

    Returns Collection<K, V>

  • Gets the first item in the collection and removes it (if provided)

    Parameters

    • Optional remove: boolean

      If we should remove it or not

    Returns undefined | V

  • Similar to [Array.some], this function tests whether atleast 1 item in the predicate function passes the test in the values cache.

    Returns

    A boolean value if 1 item of the cache is truthy

    Parameters

    • func: ((item: V) => boolean)

      The function to use to filter out

        • (item: V): boolean
        • Parameters

          • item: V

          Returns boolean

    Returns boolean

  • Similar to [Array.some], this functions tests whether atleast 1 key in the predicate function passes the test in the key cache.

    Returns

    A boolean value if 1 item of the cache is truthy

    Parameters

    • func: ((item: K) => boolean)

      The function to use to filter out

        • (item: K): boolean
        • Parameters

          • item: K

          Returns boolean

    Returns boolean

  • Similar to [Array.sort], which basically sorts the values of this Collection to return a value

    Returns

    The value

    Parameters

    • compareFn: ((a: V, b: V) => number)

      The compare function

        • (a: V, b: V): number
        • Parameters

          • a: V
          • b: V

          Returns number

    Returns V[]

  • Similar to [Array.sort], which basically sorts the values of this Collection to return a value

    Returns

    The value

    Parameters

    • compareFn: ((a: K, b: K) => number)

      The compare function

        • (a: K, b: K): number
        • Parameters

          • a: K
          • b: K

          Returns number

    Returns K[]

  • Returns all of the values as an Array

    Returns V[]

  • Returns all of the keys as an Array

    Returns K[]

  • Gets the last item in the collection and removes it(if provided)

    Parameters

    • remove: boolean

      If we should remove it or not

    Returns undefined | V

  • Returns an iterable of values in the map

    Returns IterableIterator<V>