can i combine 2 lensen to something that sets and ...
# arrow
c
can i combine 2 lensen to something that sets and gets 2 values?
s
Sadly not without it implying to
copy
twice.
Only if you write a custom instance
c
ok but that looks like it will copy twice
s
Yes, it will indeed
copy
twice. The only other way is to write a custom Optic, or to use
modify
+
copy
. For example:
Copy code
Employee.company.address.street.name
  .aside(Employee.company.address.street.number)
  .modify(json) { Pair("", 5) }

Employee.company.address.street.modify(json) {
  it.copy(name = "", number = 5)
}
Using Optics +
copy
can still give you the benefit without having to write a custom Optic. Not that it only works if you are "focusing" on a data class.
c
modify
+
copy
is really useful, thanks!