My local lens dealer's gonna be arrow?
# functional
r
My local lens dealer's gonna be arrow?
y
It's probably the easiest option available yeah. It also supports reflection-based stuff if you want that instead.
r
Can it do lenses into sealed classes where a
val
is a constructor argument to all subclasses?
aka
Copy code
sealed interface Foo {
  val x: String
  data class Bar(override val x: String)
  data class Baz(override val x: String)
}
s
Yes, that is supported!
We'll gladly deal you some optics, but we prefer to just DSL 😉 I hope to turn it into a compiler plugin down the line, and make the optics disappear all-together.
r
I've got
Copy code
@Serializable
@optics
sealed class CardMessage {
    abstract val identifier: String?
    ...
    @Serializable
    @SerialName("YoutubeVideo")
    @optics
    data class YoutubeVideo(
        val videoId: String,
        override val identifier: String? = null,
    ): CardMessage() {
        companion object
    }
}
But somehow
CardMessage.identifier
isn't being generated, all the other fields get their `Prism`s.
y
Does CardMessage have a companion object?
r
Yeah, I've got a
videoId
Prism
Ehh wait, no, I don't.
But yeah, I've got a
companion object
. Otherwise it doesn't even compile.
s
Which version are you on? Was this not backported? 🤔
r
1.2.4, should I upgrade?
s
No, 1.2.4 is fine ☺️ Let me check
Sorry, it seems that was not backported and only available from 2.0
You can work on 2.0.0-alpha.2 just fine though.
r
Switched over, synced, ran
kspKotlin
, still no
CardMessage.identifier
.
s
Can you see the generated code in
/build
?
Should be somewhere under the generated folder
If the code is there, then your ide might not be able to find it. Here is the official docs ☝️
r
It's in there, but the compiler doesn't find it even?
Weird that the other `Prism`s show up
s
Ye, you need to explicitly add it to your sourceSets in Gradle. Not sure why KSP cannot do that automatically. Hopefully we get compiler plugins soon to solve this 🤞
r
Hmm, no, it's actually added. The
identifier
isn't being created at all. I can auto-complete the other created `Prism`s
It creates a
Lens
for each individual part of the sealed object, but not the whole
s
🤯 For me it was working fine on the snippet you send above using
2.0.0-alpha.2
r
Could you try again with the full data definition? Sent via query