SelfMap<K, V> constructor

SelfMap<K, V>(
  1. Iterable<V> items, [
  2. K keyFunc(
    1. V
    )?
])

Creates a new instance of SelfMap with the provided items and keyFunc.

  • A copy of items is used to initialize the map.
  • The keys are generated using the keyFunc function, and the values are the corresponding items in the items list. if the key changes in a value, the key in map will reflect its changes.
  • If keyFunc is not provided, the default key function is used, which returns the hash code of the value.
  • The keyFunc function is used to ensure that the keys are unique. If the items list contains duplicate keys, only the first value with the key is retained.

Implementation

SelfMap(Iterable<V> items, [K Function(V)? keyFunc]) {
  this._keyFunc = keyFunc ?? ((e) => e.hashCode as K);
  this._items = items.distinctBy(this._keyFunc);
}