hashIterable method

int hashIterable(
  1. Iterable iterable, {
  2. int deep = 0,
  3. bool debug = false,
})

Implementation

int hashIterable(
  Iterable<dynamic> iterable, {
  int deep = 0,
  bool debug = false,
}) {
  int iterated = iterable.fold(
    -1,
    (int h, dynamic i) {
      int hash;
      if (i is List) {
        hash = hashIterable(i, deep: deep + 1, debug: debug);
      } else if (i is Map) {
        hash = hashIterable(i.values, deep: deep + 1, debug: debug);
      } else if (i == null) {
        hash = -2;
      } else {
        hash = i.hashCode;
      }

      int comb = combine(h, hash);

      if (kDebugMode) {
        if (debug) {
          print('${' ' * deep * 2}h: $h => '
              '(${i.runtimeType}) $i: $hash => comb: $comb');
        }
      }

      return comb;
    },
  );

  int finished = finish(iterated);

  if (kDebugMode) {
    if (debug) {
      print('finish: $finished');
    }
  }

  return finished;
}