Skip to content

Instantly share code, notes, and snippets.

@atimca
Created June 19, 2020 09:18
Show Gist options
  • Save atimca/834a3753b647a9641be1a48e40d8b07e to your computer and use it in GitHub Desktop.
Save atimca/834a3753b647a9641be1a48e40d8b07e to your computer and use it in GitHub Desktop.
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