groupByIndexedAndWhereNotNull<K> method

Map<K, List<E>> groupByIndexedAndWhereNotNull<K>(
  1. K f(
    1. E value,
    2. int index
    )
)

groupBy extension for List Grock GroupBy

Implementation

Map<K, List<E>> groupByIndexedAndWhereNotNull<K>(K Function(E value, int index) f) {
  final map = <K, List<E>>{};
  var i = 0;
  for (final element in this) {
    final key = f(element, i++);
    if (key != null) {
      map.putIfAbsent(key, () => <E>[]).add(element);
    }
  }
  return map;
}