load method

List<List<T>> load(
  1. Iterable<T> list
)

Loads a list into the ListGenerator and divides it into chunks.

Example:

List<int> myList = [1, 2, 3, 4, 5, 6, 7, 8];
ListGenerator<int> generator = ListGenerator<int>(3);
List<List<int>> parts = generator.load(myList);

Output: [[1, 2, 3],[4, 5, 6],[7, 8]]

Implementation

List<List<T>> load(Iterable<T> list) {
  final limit = max(capacity, 1);
  final n = list.length;
  final parts = <List<T>>[];
  for (int i = 0; i < n; i += limit) {
    parts.add(List<T>.from(list).sublist(i, min(n, i + limit)));
  }
  _collections = parts;
  _index = 0;
  return _collections;
}