https://kotlinlang.org logo
Title
d

dimsuz

05/08/2023, 6:43 PM
Another optics question. Prism related. I have a class such as this:
@optics
sealed class Person {
  abstract val name: String
  
  @optics
  data class Lazy(override val name: String, val days: Int) : Person()
  @optics
  data class Working(override val name: String, val hours: Int) : Person()
}
And a function to set the name
fun setName(person: Person): Person {
 return Person.lazy.name.set(
   Person.working.name.set(person, newName),
   newName
 )
}
Is this the best solution, or can I use some nice trick here in
setName
?
s

simon.vergauwen

05/09/2023, 6:12 AM
I think this is what you're looking for. https://github.com/arrow-kt/arrow/issues/2829 We still have to implement a better way for it, ideally something like
Person.name.
would work.
d

dimsuz

05/09/2023, 4:18 PM
Yes! Thank you, subscribed and +1-ed 🙂