Hi all! Could you please help me with using Optics...
# arrow
v
Hi all! Could you please help me with using Optics? I’m trying to solve the issue with deep copy of data class. My
build.gradle
has this:
Copy code
plugins {
    id "org.jetbrains.kotlin.kapt" version "1.6.0"
}
dependencies {
    implementation "io.arrow-kt:arrow-core:1.0.1"
    implementation "io.arrow-kt:arrow-optics:1.0.1"
    kapt "io.arrow-kt:arrow-meta:1.0.1"
}
Then, all data classes are annotated with
@optics
and have a companion object
Copy code
// showing a simple data class for brevity reasons
@optics
data class Mapping(
    val type: MappingType,
    val values: List<String>
) {
    companion object
}
Next, in my class when I’m trying to do this:
Copy code
val updatedMapping = Mapping.
no fields (
type
or
values
) are shown after
.
Am I missing something?
s
Hey @Vitali Plagov, That’s strange, sometimes IntelliJ will not pick up code from
kapt
and I had to apply
idea
gradle plugin. Can you see the generated code in
build/generated/kapt
?
v
Hi Simon, No, there’s no
kapt
under
build/generated
Do I have to run any gradle command or anything else once I added dependencies and annotations? I just reloaded all gradle projects and still nothing under that dir
Just run the
compileTestjava
gradle task and it works
That was unobvious (at least for me) 🙂 Thanks for the help!
s
Oh, yes. That’s a bit of an oddity about
Java annotation processing
it runs and generate actual files on-the-fly but the code is only generated after the compiler has been invoked once.
v
I guess, I don’t need to enable that setting in IDEA?
s
I have never used this flag. It should not be necessary.
👍 1
v
Btw, Simon, is it still not possible to modify several fields at once with Lens? I found your answer on SO from Sep 2019. Is it still valid?
s
That answer is still valid. We can consider moving this to Optics. @thanh has been making some improvements to Optics. Maybe we should open an issue on Github?
👍 1
v
Would be handy indeed to have an elegant API to modify several fields at once with Optics.
t
One note on Intelij not picking up generated code. I have to add something like this to build.gradle on one of my project:
Copy code
sourceSets {
    debug {
        java.srcDir(file("build/generated/source/kapt/main"))
    }
}