deepCatchesListValues<T> function

List deepCatchesListValues<T>(
  1. List? list,
  2. ValueFilter filter, [
  3. List? result
])

Catches deeply list values that matches filter.

Returns a List of the matched values

Implementation

List deepCatchesListValues<T>(List? list, ValueFilter filter, [List? result]) {
  result ??= [];

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

  for (var i = 0; i < list.length; ++i) {
    var v = list[i];
    if (filter(list, i, v)) {
      result.add(v);
    } else {
      deepCatchesValues(v, filter, result);
    }
  }

  return result;
}