zipWithConsecutivesEnclosing

fun <T, K> Iterable<T>.zipWithConsecutivesEnclosing(keySelector: (T) -> K): List<List<T>>

Zips consecutive elements of the original list by the key returned by the given keySelector function applied to each element and returns a list where each containing list holds the selected elements. If last zip and first zip have the same key, the last zip is prepended.

Receiver

contains the elements which are zipped

Return

list of all zipped elements (also represented as list), whereas the returned nested lists preserve the iteration order

Parameters

keySelector

if keySelector of consecutive elements return equal objects, zipping is performed