chunk<T> function

List<List<T>> chunk<T>(
  1. List<T> arr,
  2. int size
)

Implementation

List<List<T>> chunk<T>(List<T> arr, int size) {
  int length = (arr.length / size).ceil();

  return List<List<T>>.generate(length, (int i) {
    return arr.sublist(i * size, (i * size + size > arr.length) ? arr.length : i * size + size);
  });
}