inverse method
Inverts this map with keys becoming values and vice versa.
final foo = {'a': 1, 'b': 2, 'c': 2};
foo.inverse(); // {1: ['a'], 2: ['b', 'c']}
Implementation
@useResult Map<V, List<K>> inverse() {
final result = <V, List<K>>{};
for (final MapEntry(:key, :value) in entries) {
(result[value] ??= []).add(key);
}
return result;
}