groupListsBy<K> method Null safety

Map<K, List<T>> groupListsBy<K>(
  1. K keyOf(
    1. T element
    )
)

Groups elements into lists by keyOf.

Implementation

Map<K, List<T>> groupListsBy<K>(K Function(T element) keyOf) {
  var result = <K, List<T>>{};
  for (var element in this) {
    (result[keyOf(element)] ??= []).add(element);
  }
  return result;
}