Mikael Alfredsson
02/06/2022, 8:56 AMephemient
02/06/2022, 10:00 AMephemient
02/06/2022, 10:04 AMvar previousValue: Int? = null
list.filter { (key, value) ->
value != previousValue.also { previousValue = value }
}
will work, even if it's "cheating" a bit by using mutable state outside the lambdaMikael Alfredsson
02/06/2022, 1:31 PMFredrik Rødland
02/06/2022, 3:41 PMlistOf('a' to 1, 'b' to 1, 'c' to 2, 'd' to 2, 'e' to 1)
.fold(emptyList<Pair<Char, Int>>()) { acc, el ->
if (el.second != acc.lastOrNull()?.second) {
acc + el
} else {
acc
}
}
Paul Woitaschek
02/06/2022, 5:42 PMMikael Alfredsson
02/07/2022, 6:45 AM