flattenDepth function

List flattenDepth(
  1. Iterable list, {
  2. int depth = 1,
})

Implementation

List flattenDepth(Iterable<dynamic> list, {int depth = 1}) {
  if (depth == 0) return list.toList();
  return [
    for (var element in list)
      if (element is! Iterable)
        element
      else
        ...flattenDepth(element, depth: depth - 1),
  ];
}