SelfMap<K, V> constructor
- Iterable<
V> items, [ - K keyFunc(
- V
Creates a new instance of SelfMap with the provided items and keyFunc.
- A copy of
itemsis used to initialize the map. - The keys are generated using the
keyFuncfunction, and the values are the corresponding items in theitemslist. if the key changes in a value, the key in map will reflect its changes. - If
keyFuncis not provided, the default key function is used, which returns the hash code of the value. - The
keyFuncfunction is used to ensure that the keys are unique. If theitemslist 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);
}