Skip to content

Instantly share code, notes, and snippets.

@atimca
Created June 19, 2020 09:18
Show Gist options
  • Save atimca/2b2e9d6c5258b5d3606d3305f9fc8d10 to your computer and use it in GitHub Desktop.
Save atimca/2b2e9d6c5258b5d3606d3305f9fc8d10 to your computer and use it in GitHub Desktop.
func transform(
newsReducer: @escaping (NewsState, NewsEvent) -> NewsState,
stateKeyPath: WritableKeyPath<AppState, NewsState>
) -> Reducer {
return { appState, appEvent in
guard let newsEvent = appEvent.newsEvent 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