val elementChanges = listOf("a", "b", "b").zipWithNext { a, b ->
if(b != a) 1 else 0
}.sum()
I try to get the count of "changes" in a list in relation to one element to the next:
Here for example I see that there is a change from "a" to "b", but after that there are no changes anymore "b" to "b"
p
Pavlo Liapota
11/10/2019, 11:28 AM
Looks good to me.
Other ways to write it would be:
Copy code
listOf("a", "b", "b")
.zipWithNext { a, b -> a != b }
.count { it }
Copy code
listOf("a", "b", "b")
.zipWithNext()
.count { (a, b) -> a != b }
➕ 1
d
Daniel
11/10/2019, 12:29 PM
Thank you for your suggestions! They are also good possibilities