Colton Idle
08/23/2022, 7:35 AMstate.myList[index] = state.myList[index].copy(isFollowing = !state.myList[index].isFollowing!!)
A lot of ceremony just to flip the value of isFollowing
Sam
08/23/2022, 7:39 AMSam
08/23/2022, 7:44 AMSam
08/23/2022, 7:49 AMfun <T> MutableList<T>.update(i: Int, f: (T) -> T) {
this[i] = f(this[i])
}
Then you can write
state.myList.update(index) {
it.copy(isFollowing = !it.isFollowing!!)
}
Colton Idle
08/23/2022, 7:54 AMRob Elliot
08/23/2022, 9:20 AMstate.myList[index]
to flip the status of `isFollowing`:
fun MyType.toggleFollowing() = copy(isFollowing = !isFollowing)
Then it's:
state.myList.update(1) { it.toggleFollowing() }
August Lilleaas
08/23/2022, 11:01 AM