If you are working with Redux, the state definition is a key task in the design of your application. Once the state is defined, the reducers are the next step, setting how the state will change according to the inputs received. If your state is too complex, is better to group the logic in two or more reducers and then use something like the following code:
val newState = combineReducers(::reducerA, ::reducerB)(action, oldState)
In this way, the method
combineReducers will accept as many reducers needed, connecting the output of one reducer to the input of the next one in the list. All of them will modify the state in a functional and testable way and the logic will be separated in smaller modules.
Let’s define the Reducer interface and the combineReducers method for Kotlin:
If a concept is exported from the web and JS world (Redux in this case) then many solutions will be found in the same place (original Redux documentation). Besides, Kotlin and Swift give enough flexibility to reproduce any solution needed.