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

Filip Wiesner

01/06/2022, 7:32 AM
Weird question. Is
remember { ... }
equal to
remember(Unit) { ... }
? Or does the
Unit
key override the implicit key derived from call order? Am I just overthinking things?
👌 2
👀 1
f

Filip Wiesner

01/06/2022, 8:58 AM
So I guess the answer is: Yes, it's the same and yes I am overthinking it 🙂
🥲 2
👍 3
c

Chuck Jazdzewski [G]

01/06/2022, 11:53 PM
They have the same result but
remember { ... }
is more efficient as it doesn't needlessly store
Unit
in the slot table and compare it. In both cases
remember
can be thought of as implicitly having a key that is its position in composition (the inspiration for the the name "positional memoization"). Adding a key to
remember
does not replace the positional key, it adds to it to form a composite key that when the composite key changes the lambda is reinvoked to produce a new value.
today i learned 1
f

FunkyMuse

01/07/2022, 4:34 PM
@Chuck Jazdzewski [G] so the key inside remember is basically a primary key that is added by the compiler, if you provide an additional key yourself then it becomes composite key, something like in an SQL database?
c

Chuck Jazdzewski [G]

01/07/2022, 5:22 PM
Yes; that is the idea. The positional key is implied by the location where the
remember
appears in the composable function call graph. Since the slot table stores a linear record of the call graph, the location in the slot table is sufficient to determine which remember is being referenced.
🙏 1
f

Filip Wiesner

01/07/2022, 6:41 PM
Thanks for detailed answer, Chuck 👍 I really appreciate it. Now it seems like my question wasn't as stupid as I thought 😅
4 Views