isEquivalentList function

bool isEquivalentList(
  1. List? l1,
  2. List? l2, {
  3. bool sort = false,
  4. bool deep = false,
})

Returns true if l1 and l2 are equals, including the same position for the elements.

sort If true sorts l1 and l2 before check. deep If true checks deeply collections elements.

Implementation

bool isEquivalentList(List? l1, List? l2,
    {bool sort = false, bool deep = false}) {
  if (l1 == l2) return true;

  if (l1 == null) return false;
  if (l2 == null) return false;

  var length = l1.length;
  if (length != l2.length) return false;

  if (sort) {
    l1.sort();
    l2.sort();
  }

  for (var i = 0; i < length; ++i) {
    var v1 = l1[i];
    var v2 = l2[i];

    if (!isEquals(v1, v2, deep)) return false;
  }

  return true;
}