I am trying to set up `Lens` code generation in my...
# arrow
a
I am trying to set up
Lens
code generation in my little learning project. The docs seem to be outdated. This is the commit that attempts it: https://github.com/adomokos/kotlin-sandbox/commit/0ac6eca63e7fffc83db113fd87ba3972807a22a2 What am I missing?
j
You need a
companion object
on those classes for codegen to work afaik. Also I don't think the generated-sources part is still relevant
So
@optics data class LaptopL(val price: Double, val motherBoardL: MotherBoardL) { companion object }
should work. There are some other restrictions as to how the classes used in the fields should look, but I haven't used optics enough to list those correctly. Maybe @simon.vergauwen knows more
s
Ah you’re using kapt in tests. I think you need additional setup to include the generated sources into the test sources
👍 1
a
True. Is that more of a gradle issue then?
s
Yes, I am going to check but it involves adding more sources in
generated-kotlin-sources.gradle
a
Thanks @Jannis and @simon.vergauwen for chiming in.
s
Now you’re only adding them to
sourceDirs
but I think you also need to add them to
testDirs
or something like that
a
I see.
s
And you need to add the dependency to kapt for testing
kaptTest project(':arrow-meta')
I just tried in the Arrow project and by adding that it automatically generated the sources
❤️ 1
You can verify if the code was generated in the build folder
a
👀
Thank you both for your help. This commit has a passing test using the generated code from Optics: https://github.com/adomokos/kotlin-sandbox/commit/5291f6f05b6d8a249abe0fd9fd41812ddcf7f15e
I really should blog about this. This little project has working examples others could check out. Maybe not generating the optics code in tests, but I think others could find it useful.
s
Ah that’s awesome! This would be a useful addition to the Arrow documentation as well, this information is completely missing atm.
You’re very welcome! And if you decide to write a blog post feel free to poke for help and don’t forget to PR it to https://arrow-kt.io/blog/ 😉
a
Sure thing! Getting this code generated from
@optics
via
kapt
was the most complex task I've bumped into.
s
With Arrow Meta that pain should also all be levitated since we can configure it through a Gradle plugin.
💥 1
a
What is the easiest way to check out the new documentation that I've heard is brewing? I would love to start contributing to it.
❤️ 2
s
cc\ @raulraja
Need to call help for this question 😅
r
In the future we will be able to automatically derive all optics for all data classes including the companion DSL with either Quote Transformation to generate the lenses or type proof extensions which are like type classes and can inductively derive extensions based on shape for all data and sealed.classes or anything considered a product and Coproduct type in Kotlin
We are working on that now in meta in the type conversions branch
Inductive resolution of proof constrains that can perform autoderivation