Lua-Collections icon indicating copy to clipboard operation
Lua-Collections copied to clipboard

Collection:split() with even groups

Open imliam opened this issue 8 years ago • 0 comments

It would be useful to be able to optionally alter the behaviour of Collection:split() by passing a 2nd argument to the method so that the chunks it returns are as evenly as possible.

Currently, the resulting chunks are first-heavy:

collect({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}):split(3):all()
-- { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10} }

The intended behaviour with true passed as the 2nd argument would even out the number of values in each chunk:

collect({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}):split(3, true):all()
-- { {1, 2, 3, 4}, {5, 6, 7}, {8, 9, 10} }

imliam avatar May 17 '17 15:05 imliam