It seems that it is impossible to use `@optics` to...
# arrow
m
It seems that it is impossible to use
@optics
to generate optics for generic data classes and sealed classes. The generated code has compiler errors. 1) is this right? and 2) are there alternatives to this besides writing the optics by hand?
👍 1
hey @pakoito, Brandon from twitter 👋. you told me to ask this question in slack to see if Simon would have ideas.
p
cc @simon.vergauwen, although he hasn’t been around today from what I’ve seen
m
thanks!
s
Hi Brandon, Couple of busy days. That should not be the case, I was using
@optics
myself yesterday successfully on
0.10.4
. Could you provide some more details on the compile errors? Did you add a
companion object
to all your
data classes
and
sealed classes
? Those markers need to be present to generate the code, and I saw yesterday the compile error was surrounded by other Gradle message, we should probably show a header or some whitelines around it to make it better visual.
m
@simon.vergauwen no worries, thanks for the info! i’m pretty sure i had everything set up correctly, but I will double check and get back to you. thanks again!
Hey Simon, so I can’t get it to work. In case you missed it, this is about generating optics for generic data classes and sealed classes. for example this:
Copy code
@optics
data class Foo<A>(
    val value: A,
    val timestamp: Int
) {
    companion object
}
generates an optic that looks like this:
Copy code
inline val `com`.`example`.`search_popular`.`Foo`.Companion.iso: arrow.optics.Iso<`com`.`example`.`search_popular`.`Foo`, arrow.core.Tuple2<`A`, `kotlin`.`Int`>> inline get()= arrow.optics.Iso(
  get = { foo: `com`.`example`.`search_popular`.`Foo` -> arrow.core.Tuple2(foo.`value`, foo.`timestamp`) },
  reverseGet = { tuple: arrow.core.Tuple2<`A`, `kotlin`.`Int`> -> `com`.`example`.`search_popular`.`Foo`(tuple.a, tuple.b) }
)
which does not properly give
Foo
its generic. are optics for generic types supposed to work?
s
Hey Brandon, Sadly that is correct. There is no support for generating
@optics
for polymorphic products or sum types
m
@simon.vergauwen ah ok, thanks for the confirmation! good to know
s
@mbrandonw after a chat with @raulraja I remember this was due to the limitations in
kapt
. With Arrow-meta and the full Kotlin compiler support we can more easily also derive these more complex optics. So hopefully later this year we can support polymorphic optics automatically.
m
@simon.vergauwen oh awesome, thanks for the info. can’t wait for that!
👍 1