mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
19 lines
409 B
Dart
19 lines
409 B
Dart
extension ListExt<T> on List<T> {
|
|
List<List<T>> chunked({required int chunkSize}) {
|
|
final remainder = length % chunkSize;
|
|
final count = length ~/ chunkSize;
|
|
final List<List<T>> result = [];
|
|
|
|
int i = 0;
|
|
while (i < count) {
|
|
result.add(sublist(i, i + chunkSize));
|
|
i++;
|
|
}
|
|
|
|
if (remainder > 0) {
|
|
result.add(sublist(i, i + remainder));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|