deepReplaceListValues<T> function

void deepReplaceListValues<T>(
  1. List? list,
  2. ValueFilter filter,
  3. ValueReplacer replacer
)

Replaces values applying replacer to values that matches filter.

Implementation

void deepReplaceListValues<T>(
    List? list, ValueFilter filter, ValueReplacer replacer) {
  if (list == null || list.isEmpty) return;

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