buffer method

List<List<T>> buffer(
  1. int count
)

count数给列表分组

Implementation

List<List<T>> buffer(int count) {
  final result = <List<T>>[];

  final totalRound = (length / count).ceil();
  for (int i = 0; i < totalRound; i++) {
    final round = <T>[];
    for (int j = (i * count); j < ((i + 1) * count); j++) {
      if (j < length) {
        round.add(elementAt(j));
      } else {
        break;
      }
    }
    result.add(round);
  }

  return result;
}