deepReplaceSetValues<T> function

void deepReplaceSetValues<T>(
  1. Set? set,
  2. ValueFilter filter,
  3. ValueReplacer replacer
)

Replaces values applying replacer to values that matches filter.

Implementation

void deepReplaceSetValues<T>(
    Set? set, ValueFilter filter, ValueReplacer replacer) {
  if (set == null || set.isEmpty) return;

  var entries = set.toList();

  for (var val in entries) {
    Object? val2;
    if (filter(set, null, val)) {
      val2 = replacer(set, null, val);
    } else {
      val2 = deepReplaceValues(val, filter, replacer);
    }

    if (!identical(val, val2)) {
      set.remove(val);
      set.add(val2);
    }
  }
}