mergeDataDeep function

dynamic mergeDataDeep(
  1. dynamic a,
  2. dynamic b, [
  3. dynamic elseFilter(
    1. dynamic
    )?
])

Merges two data structures deeply.

Implementation

dynamic mergeDataDeep(
  dynamic a,
  dynamic b, [
  dynamic Function(dynamic)? elseFilter,
]) {
  if (a is Map && b is Map) {
    return mergeMaps(
      a,
      b,
      value: (a, b) {
        if (a is Map && b is Map) {
          return mergeDataDeep(a.nonNulls, b.nonNulls, elseFilter);
        }
        if (a is List || a is Set || a is Queue) {
          return mergeListsSetsOrQueues(a as Iterable, b as Iterable);
        }
        if (a is Iterable) {
          return mergeIterables(a, b);
        }
        return elseFilter?.call(b) ?? b;
      },
    );
  }
  if (a is List || a is Set || a is Queue) {
    return mergeListsSetsOrQueues(a as Iterable, b as Iterable);
  }
  if (a is Iterable) {
    return mergeIterables(a, b);
  }
  return elseFilter?.call(b) ?? b;
}