gqlifyDeepEquals function

bool gqlifyDeepEquals(
  1. Object? a,
  2. Object? b
)

Deep equality for (possibly nested) lists, maps and sets of generated or JSON values.

Implementation

bool gqlifyDeepEquals(Object? a, Object? b) {
  if (identical(a, b)) return true;
  if (a is List && b is List) {
    if (a.length != b.length) return false;
    for (var i = 0; i < a.length; i++) {
      if (!gqlifyDeepEquals(a[i], b[i])) return false;
    }
    return true;
  }
  if (a is Map && b is Map) {
    if (a.length != b.length) return false;
    for (final key in a.keys) {
      if (!b.containsKey(key) || !gqlifyDeepEquals(a[key], b[key])) {
        return false;
      }
    }
    return true;
  }
  if (a is Set && b is Set) {
    return a.length == b.length && a.containsAll(b);
  }
  return a == b;
}