groupBy<T, K> static method
Groups list into a map keyed by the value returned by by.
Arr.groupBy(messages, (m) => m.date);
// {2024-01-01: [...], 2024-01-02: [...]}
Implementation
static Map<K, List<T>> groupBy<T, K>(Iterable<T> list, K Function(T) by) {
final result = <K, List<T>>{};
for (final v in list) {
result.putIfAbsent(by(v), () => <T>[]).add(v);
}
return result;
}