How up-to-date is "Looking into immutable data wit...
# arrow
c
How up-to-date is "Looking into immutable data with Optics" from @simon.vergauwen from two years ago?
s
It's fairly up-to-date, but doesn't go super deep. The Optics library hasn't had a lot of change since it was first added in 2017.
c
Thanks 👍
So far I've gone through the basics of what
@optic
does to a data class, but I'm not sure how to jump from that to how to 'mutate' trees
s
It doesn't mutate long story short, it composes function that together build a very complex copy that you would otherwise have to write by hand.
c
Sorry, I understand it's all just copy, but I'm not sure how you get to actually doing it. We'll see if the video clears that up 🙂
s
Ah, that is a bit harder to explain. It also depends heavily on which optic you compose together. My original goal when I started building Arrow Optics (I named it Optikal at the time) was to understand how optics worked 🙃
c
And… did you understand it? 😂 Am I right to expect that after writing this code:
Copy code
@optics
data class Test(val name: String) {
	companion object
}
I should be able to type:
Copy code
Test.name
or did I forget something?
s
Yes, I understand it after building it 😄 Yes, you should but you need to setup KSP correctly. Can be a bit tedious. https://arrow-kt.io/docs/optics/#step-3-add-the-plug-in-optional https://kotlinlang.org/docs/ksp-quickstart.html#make-ide-aware-of-generated-code
c
Ah, my KSP is too old.
Manually adding the generated files to the source files doesn't seem to be necessary anymore
Optics do not work on private classes?
s
Oh, interesting. No it's impossible to generate code for a private (file) class.
Since it goes in a different file
c
KSP is actually generating Kotlin code? I thought it generated bytecode directly
I guess that's why everyone is waiting for compiler plugins 🙂
nevermind, adding the generated source sets is still necessary