Another optics question. Prism related. I have a ...
# arrow
d
Another optics question. Prism related. I have a class such as this:
Copy code
@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
Copy code
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
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
Yes! Thank you, subscribed and +1-ed 🙂