Last active
July 15, 2021 23:53
-
-
Save riscait/50d2a17b7212e889dbfd64a81fa31fe7 to your computer and use it in GitHub Desktop.
Chunk list by do-while
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| final items = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']; | |
| final chunkedItems = []; | |
| final chunkSize = 3; | |
| var count = 0; | |
| do { | |
| chunkedItems.add(items.skip(count).take(chunkSize).toList()); | |
| count += chunkSize; | |
| } while (count < items.length); | |
| print(chunkedItems); // [[a, b, c], [d, e, f], [g, h, i], [j, k]] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment