deepCatchesMapValues<T> function

List deepCatchesMapValues<T>(
  1. Map? map,
  2. ValueFilter filter, [
  3. List? result
])

Catches deeply map values that matches filter.

Returns a List of the matched values

Implementation

List deepCatchesMapValues<T>(Map? map, ValueFilter filter, [List? result]) {
  result ??= [];

  if (map == null || map.isEmpty) return result;

  for (var entry in map.entries) {
    var k = entry.key;
    var v = entry.value;
    if (filter(map, k, v)) {
      result.add(v);
    } else {
      deepCatchesValues(v, filter, result);
    }
  }

  return result;
}