Created
June 14, 2019 13:26
-
-
Save oleksii-demedetskyi/cbf1b339ee407838e6597dbe00f9ecc3 to your computer and use it in GitHub Desktop.
This file contains 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
protocol _Reducer { | |
associatedtype State | |
associatedtype Action | |
func reduce(state: inout State, action: Action) | |
} | |
protocol Reducer: _Reducer where State == Body.State, Action == Body.Action { | |
associatedtype Body: Reducer | |
var body: Body { get } | |
} | |
extension Reducer { | |
func reduce(state: inout State, action: Action) { | |
body.reduce(state: &state, action: action) | |
} | |
} | |
struct ConcreteReducer<State, Action>: Reducer { | |
let performReduce: (inout State, Action) -> Void | |
var body: Self { self } // ??? | |
func reduce(state: inout State, action: Action) { | |
performReduce(&state, action) | |
} | |
} | |
// ERROR: 'Reducer' requires the types 'Action' and ' | |
// (some Reducer).Action' be equivalent | |
struct EmptyRedcer<State, Action>: Reducer { | |
var body: some Reducer { | |
ConcreteReducer<State, Action> { state, action in | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment