combineReducers

fun <State, Action : Any, S1, S2> combineReducers(reducer1: ChildReducer<State, Action, S1>, reducer2: ChildReducer<State, Action, S2>, transform: (S1, S2) -> State): Reducer<State, Action>

Turns two Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.

An example:

val reducer = combineReducers(
child(reducer1) { it.child1 },
child(reducer2) { it.child2 }
) { child1, child2 ->
State(child1, child2)
}

The example above is equivalent to:

val reducer = Reducer(
State(reducer1.initialState, reducer2.initialState)
) { acc, action ->
State(
reducer1.reduce(acc.child1, action),
reducer2.reduce(acc.child2, action),
)
)

This can also map parent actions to child actions. If the mapToChildAction]returns null, the child reducer will not be called.

val reducer = combineReducers(
child(
reducer1,
mapToChildAction = { it as? ParentAction.Child1 },
mapToChildState = { it.child1 }
),
child(
reducer2,
mapToChildAction = { it as? ParentAction.Child2 },
mapToChildState = { it.child2 }
)
) { child1, child2 ->
State(child1, child2)
}

fun <State, Action : Any, S1, S2, S3> combineReducers(reducer1: ChildReducer<State, Action, S1>, reducer2: ChildReducer<State, Action, S2>, reducer3: ChildReducer<State, Action, S3>, transform: (S1, S2, S3) -> State): Reducer<State, Action>

Turns three Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.


fun <State, Action : Any, S1, S2, S3, S4> combineReducers(reducer1: ChildReducer<State, Action, S1>, reducer2: ChildReducer<State, Action, S2>, reducer3: ChildReducer<State, Action, S3>, reducer4: ChildReducer<State, Action, S4>, transform: (S1, S2, S3, S4) -> State): Reducer<State, Action>

Turns four Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.


fun <State, Action : Any, S1, S2, S3, S4, S5> combineReducers(reducer1: ChildReducer<State, Action, S1>, reducer2: ChildReducer<State, Action, S2>, reducer3: ChildReducer<State, Action, S3>, reducer4: ChildReducer<State, Action, S4>, reducer5: ChildReducer<State, Action, S5>, transform: (S1, S2, S3, S4, S5) -> State): Reducer<State, Action>

Turns five Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.


fun <State, Action : Any, S> combineReducers(vararg reducers: ChildReducer<State, Action, S>, transform: (List<S>) -> State): Reducer<State, Action>

Turns multiple Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.