deepCopy<T> function

T? deepCopy<T>(
  1. T? o, {
  2. Copier? copier,
})

Deeply copies o.

copier Copy Function for non-primitive types.

Implementation

T? deepCopy<T>(T? o, {Copier? copier}) {
  if (o == null) return null;
  if (o is String) return o;
  if (o is num) return o;
  if (o is bool) return o;

  if (o is List) return deepCopyList(o, copier: copier) as T?;
  if (o is Map) return deepCopyMap(o, copier: copier) as T?;

  if (copier != null) {
    return copier(o);
  } else {
    return o;
  }
}