parts<T> static method
Part array
Implementation
static List<List<T>> parts<T>(List<T> colls, int parts) {
if (colls.isEmpty) {
return List.empty();
}
if (parts <= 0) {
throw ArgumentError('the parts length must > 0');
}
if (colls.length <= parts) {
return [colls];
}
List<List<T>> rets = [];
List<T> items = [];
var pnum = (colls.length / parts).floor();
for (var coll in colls) {
items.add(coll);
if (items.length == pnum) {
rets.add(items);
if (rets.length < parts) {
items = [];
}
}
}
return rets;
}