Copying this from <#C1JMF6UDV|functional> as it di...
# random
n
Copying this from #functional as it didn't get any response 😛 How would one implement a
bufferUntilChanged
with either manual iteration or, preferably, stdlib operators? As an example:
listOf(1,1,1,2,2,5,2,2,2,1,1,1,3,3,3).bufferUntilChanged() = [[1,1,1],[2,2],[5],[2,2,2],[1,1,1],[3,3,3]]
I feel like the new `pairwise`operator from the 1.2 EAP could be useful but I can't come up with a clean way of doing this Thread in Slack Conversation gsala:
fun List<Int>.bufferUntilChanged() = fold(mutableListOf(mutableListOf<Int>())) { ll, v -> val l = ll.last(); if (l.isEmpty() || l.first() == v) { l += v } else { ll += mutableListOf(v) }; ll }