Created
March 31, 2019 14:59
-
-
Save monday8am/9827bc69b51fe88b8726c9d05265492a to your computer and use it in GitHub Desktop.
CombineReducer method in Kotlin
This file contains hidden or 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