<@U5YK0BHL5> Something along these lines: ``` fun ...
# functional
r
@gsala Something along these lines:
Copy code
fun List<Int>.bufferUntilChanged(): List<List<Int>> =
        this.foldIndexed(emptyList<List<Int>>(), { index, acc, n ->
            if (index > 0) {
                val previous: Int = this[index - 1]
                if (previous == n && acc.isNotEmpty()) {
                    val currentBuffer = acc.last() + n
                    val prevBuffers = acc.dropLast(1)
                    prevBuffers + listOf(currentBuffer)
                } else {
                    acc + listOf(listOf(n))
                }
            } else {
                acc + listOf(listOf(n))
            }
        })