countBy static method

Map countBy(
  1. Iterable itr,
  2. dynamic fn(
    1. dynamic
    )
)

counts the occurrences of values in the list if condition satisified

Example:

countBy(list, fn)

Implementation

static Map<dynamic, dynamic> countBy(
    Iterable<dynamic> itr, dynamic Function(dynamic) fn) {
  // ignore: always_specify_types
  return Map.fromIterable(itr.map(fn).toSet(),
      // ignore: always_specify_types
      value: (i) => itr.where((v) => fn(v) == i).length);
}