tseisel
10/12/2020, 2:09 PMfun <T> listDiff(original: List<T>, revised: List<T>): List<DiffOp<T>>
sealed class DiffOp<T> {
class Add<T>(val element: T, val index: Int) : DiffOp<T>()
class Remove<T>(val element: T, val index: Int) : DiffOp<T>()
}
I find myself needing this kind of feature quite often. I've searched the web like crazy, but it seems that Myer's Diff Algorithm has only been implemented for diffing text, not collections.
Swift's standard library implements it as CollectionDifference. Maybe this could be a nice library to have for Kotlin Multiplatform ?Vampire
10/12/2020, 2:30 PMval x = listOf(1, 2, 3)
val y = listOf(2, 4, 5)
val added = y - x
val removed = x - y
tseisel
10/12/2020, 2:33 PMtseisel
10/12/2020, 2:34 PMarekolek
10/12/2020, 2:34 PMVampire
10/12/2020, 2:54 PMarekolek
10/12/2020, 5:25 PM