```val newState = state.copy( items = state.items...
# android-architecture
u
Copy code
val newState = state.copy(
	items = state.items.map {
		if (it.id == id) {
			it.copy(
				text = newText
			)
		} else {
			it
		}
	}
)
t
The correct answer is to use optics/lenses and datatype generic programming (à la SYB or generics-sop in Haskell lingo). I think arrow has lenses, although they were quite annoying to use last time I checked. So it may be better to wait a few more months until arrow-meta and such stabilizes and a nicer lens API may be released.
Basically, lenses are composable copy-set methods, such that for
setItem:  State.(Item) -> State
and
setId: Item.(Id) -> Item
you can compose them to a method
setItemId: State.(Id) -> State
.
u
what would be the syntax ..
item = item.setId
?
t
something like that. I only know them from Haskell