CombineReducer method in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Reducer interface definition | |
// | |
typealias Reducer<ReducerStateType> = (action: Action, state: ReducerStateType?) -> ReducerStateType | |
// | |
// Combine reducers method | |
// | |
fun<T: StateType> combineReducers(vararg reducers: Reducer<T>): Reducer<T> { | |
return { action, state -> | |
var newState: T? = state | |
reducers.forEach { reducer -> | |
newState = reducer(action, newState) | |
} | |
newState!! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment