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
items
is used to initialize the map. - The keys are generated using the
keyFunc
function, and the values are the corresponding items in theitems
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 theitems
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);
}