Skip to content

Instantly share code, notes, and snippets.

@monday8am
Created March 31, 2019 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monday8am/9827bc69b51fe88b8726c9d05265492a to your computer and use it in GitHub Desktop.
Save monday8am/9827bc69b51fe88b8726c9d05265492a to your computer and use it in GitHub Desktop.
CombineReducer method in Kotlin
//
// 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