Sergey Shevtsov
06/21/2023, 11:40 AM@Immutable
@optics
data class ViewState(
val someValue: Map<String, AnotherDataClass>
)
@Immutable
@optics
data class AnotherDataClass(
val someList: List<String>
)
How can i change multiple values in this map in 1 operation using Arrow?dave08
06/21/2023, 11:42 AMSergey Shevtsov
06/21/2023, 12:07 PM@Immutable
@optics
data class ViewState(
val key: SomeKey,
val someValue: Map<SomeKey, AnotherDataClass>
)
enum class SomeKey { Key1, Key2 }
ViewState.someValue.every(Every.map).modify(state) { value ->
val newList = when (value.key) {
Key1 -> listOf(1, 2, 3)
Key2 -> listOf(4, 5, 6)
}
AnotherDataClass.someList.set(value, newList)
}
This is fine? Or is there a better solution here?dave08
06/21/2023, 12:10 PMcopy { ... }
method on your ViewState?dave08
06/21/2023, 12:12 PMSergey Shevtsov
06/21/2023, 12:33 PMprivate fun ViewState.setValues(list1: List<String>, list2: List<String>): ViewState = copy {
ViewState.someValue.index(Index.map(), Key1).someList set list1
ViewState.someValue.index(Index.map(), Key2).someList set list2
}
dave08
06/21/2023, 12:42 PMSergey Shevtsov
06/21/2023, 12:44 PM