chunkedBy

inline fun <T, K> Iterable<T>.chunkedBy(selector: (T) -> K): List<List<T>>

Splits this iterable into consecutive runs, starting a new run whenever the value of selector changes.

Elements are kept in encounter order and every element appears in exactly one run. An empty receiver yields an empty list.