flattenDepth<T> function
Recursively flatten array up to depth times.
It returns newObject
of flattened array and does not affects the list object called-upon
var list = [2, [1, 3], [4, [1, [2]] ] ];
var newList = flattenDepth(list, 1); // newList = [2, 1, 3, 4, [1, [2] ] ];
Implementation
List<T>? flattenDepth<T>(List<T> list, [int depth = 1]) {
return list.flattenDepth(depth) as List<T>?;
}