Daniel
11/10/2019, 10:44 AMval 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"Pavlo Liapota
11/10/2019, 11:28 AMlistOf("a", "b", "b")
.zipWithNext { a, b -> a != b }
.count { it }
listOf("a", "b", "b")
.zipWithNext()
.count { (a, b) -> a != b }
Daniel
11/10/2019, 12:29 PMMilan Hruban
11/10/2019, 8:54 PMlistOf("a", "b", "b")
.windowed(size = 2, step = 1)
.count { it.distinct().size == 2 }
because then the "windowSize" (2 in this case) could be extracted to parameterDaniel
11/11/2019, 7:24 PM