mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-28 14:29:22 +00:00
20 lines
409 B
Dart
20 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;
|
||
|
}
|
||
|
}
|