asMapOfLists<K> method
Returns an ImmortalMap using the given keyGenerator
and concatenating
values with the same key.
Iterates over all elements in iteration order and calculates the key for
each element by applying keyGenerator
to its value. The list of all
values with the same key in iteration order is used as the value of the
generated key in the resulting map.
Implementation
ImmortalMap<K, ImmortalList<T>> asMapOfLists<K>(
K Function(T value) keyGenerator) =>
fold(
ImmortalMap<K, ImmortalList<T>>(),
(map, value) => map.update(
keyGenerator(value),
(list) => list.add(value),
ifAbsent: () => ImmortalList([value]),
),
);