Map<K, List<V>> groupBy<K>(K keyOf(V value)) { final result = <K, List<V>>{}; for (final item in this.orEmpty()) { result.putIfAbsent(keyOf(item), () => <V>[]).add(item); } return result; }