eachCount method

Map<K, int> eachCount()

Groups elements by key and counts the elements in each group.

final words = 'one two three four five six seven eight nine ten'.split(' ');
final frequenciesByFirstChar =
    words.groupingBy((value) => value[0]).eachCount();

print('Counting first letters:');
print(frequenciesByFirstChar); // {o=1, t=3, f=2, s=2, e=1, n=1}

Implementation

Map<K, int> eachCount() {
  return group.map((key, value) => MapEntry(key, value.length));
}