/**
* Groups elements in chunks of up to `n` elements.
*
* @tsplus static Chunk.Aspects grouped
* @tsplus pipeable Chunk grouped
*/
export function grouped(n: number) {
return (self: Chunk): Chunk> => {
let gr = Chunk.empty>()
let current = Chunk.empty()
self.forEach((a) => {
current = current.append(a)
if (current.size >= n) {
gr = gr.append(current)
current = Chunk.empty()
}
})
if (current.size > 0) {
gr = gr.append(current)
}
return gr
}
}