copy

fun <A> A.copy(f: Copy<A>.() -> Unit): A(source)

Small DSL which parallel Kotlin's built-in copy, but using optics instead of field names. See Copy for the operations allowed inside the block.

This allows declaring changes on nested elements, preventing the "nested copy problem". Instead of:

person.copy(address = person.address.copy(city = "Madrid"))

you can write:

person.copy {
Person.address.city set "Madrid"
}