deepCopy method

List<T> deepCopy({
  1. T mapCopy(
    1. T
    )?,
})

To do a deep copy, you first need to copy the collection. If the target copy object mapCopy is null, the collection will be copied directly. Otherwise, the collection itself needs to be copied, and the elements inside the collection also need to be copied.

Implementation

List<T> deepCopy({T Function(T)? mapCopy}) {
  List<T> list = [];
  if (mapCopy.isNull) {
    for (var i = 0; i < length; i++) {
      list.add(this[i]);
    }
  } else {
    for (var i = 0; i < length; i++) {
      list.add(mapCopy!.call(this[i]));
    }
  }
  return list;
}