https://kotlinlang.org logo
#compose
Title
# compose
h

hfhbd

01/05/2022, 2:27 PM
Compose Compiler can compare a tree of nodes. But can it compare different nodes with built-in lists of other nodes too? Usecase:
data class Foo(val bar: List<Bar>) { data class Bar(val i: Int) }
Can Compose generate the difference of
Foo(emptyList())
and
Foo(listOf(Bar(1))
and
Foo(listOf(Bar(42))
? At the end, I would like to use Compose as a general tree diff tool with my own tree implementation by using difference instances of my tree.
z

Zach Klippenstein (he/him) [MOD]

01/07/2022, 5:33 PM
Compose doesn't compare trees of nodes. It generates effectively change lists by performing composition, then applies those changes to the tree. So to answer your question, nope. Compose is not a diff tool.
h

hfhbd

01/08/2022, 10:03 AM
Ah, okay. But would you able do use it as a diff tool too, iff the data is not given, but generated during compositions? With a custom compose applier, you could store the changes and return it later?
z

Zach Klippenstein (he/him) [MOD]

01/10/2022, 8:07 PM
Compose generates and updates a tree data structure from an execution of composable functions. Trying to use it for something else might work, but will probably be pretty hacky and more complex than it's worth
11 Views