Created
June 19, 2020 09:18
-
-
Save atimca/834a3753b647a9641be1a48e40d8b07e to your computer and use it in GitHub Desktop.
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
func transform( | |
newsReducer: @escaping (NewsState, NewsEvent) -> NewsState, | |
stateKeyPath: WritableKeyPath<AppState, NewsState>, | |
toNewsEvent: @escaping (AppEvent) -> NewsEvent? | |
) -> Reducer { | |
return { appState, appEvent in | |
guard let newsEvent = toNewsEvent(appEvent) else { return appState } | |
var appState = appState | |
appState[keyPath: stateKeyPath] = newsReducer(appState[keyPath: stateKeyPath], newsEvent) | |
return appState | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment