Map<K, List<T>> groupBy<K>(K Function(T) fn) => fold( <K, List<T>>{}, (Map<K, List<T>> map, T element) => map..putIfAbsent(fn(element), () => <T>[]).add(element));