Is there any way Either could be declared with a c...
# arrow
d
Is there any way Either could be declared with a compose stability annotation (it doesn't require any dependency to the runtime, there's a seperate annotation module for kmp...). It seems like compose thinks Either is unstable...!
a
sure thing! could you provide some pointers on how to do this?
This is the dependency:
Copy code
androidx-compose-runtime-annotation = { group = "androidx.compose.runtime", name = "runtime-annotation", version = "1.10.0" }
(I think that version is the current stable one)
Thanks!
s
You can use a stability configuration file to fix this on your end:
Copy code
<https://developer.android.com/develop/ui/compose/performance/stability/fix#configuration-file>
d
Interesting! I didn't notice that one... but it still would be nice to have this (maybe provided like that in the arrow compose module, since the dep is already there... would that work @stojan?) to avoid all arrow users to have to maintain their own list...
s
This is what Compose recommends for multi-module and/or libraries:
Copy code
<https://developer.android.com/develop/ui/compose/performance/stability/fix#multiple-modules>
I typically deal with Either on the ViewModel level, and keep my views dumb -> Meaning Either gets transformed to some other class that represents the UI (in case of a Left this is still just a class, but it's rendered as an error view in the UI). Do you often have either as part of the UI models?
a
unfortunately, it seems that there's no annotation for "parametric stabilty" in Compose. Because the right thing here is to make
Either<A, B>
immutable or stable only if the types inside are immutable or stable, respectively
so it seems the only option is marking your data types containing
Either
manually, as far as I understand
d
Yeah, I guess... although, normally functional programming doesn't really encourage mutable states, no?
a
still, we cannot mark it as @Immutable or @Stable, because there's a risk of being wrong
d
Yeah, I guess, maybe I should really avoid using them in compose uis then. It's always a risk that another programmer might not understand how to use Either in an immutable way and shoot himself in the foot if I mark it immutable myself.
a
I think it's OK if you use an
Either
inside another class, and you mark that one as stable