chunkedBy

fun <E> Iterable<E>.chunkedBy(selector: (E) -> Boolean): List<List<E>>(source)

This function iterates over the receiver iterable and adds each element to the current chunk. Whenever the selector function returns true for an element, that element concludes the current chunk and a new chunk is started.

Receiver

The iterable to be split into chunks.

Return

A list of chunks, where each chunk is a list of elements from the receiver iterable.

Parameters

selector

A function that determines when to conclude the current chunk and start a new one.