Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. protocol _Reducer {
  2. associatedtype State
  3. associatedtype Action
  4.  
  5. func reduce(state: inout State, action: Action)
  6. }
  7.  
  8. protocol Reducer: _Reducer where State == Body.State, Action == Body.Action {
  9. associatedtype Body: Reducer
  10.  
  11. var body: Body { get }
  12. }
  13.  
  14. extension Reducer {
  15. func reduce(state: inout State, action: Action) {
  16. body.reduce(state: &state, action: action)
  17. }
  18. }
  19.  
  20. struct ConcreteReducer<State, Action>: Reducer {
  21. let performReduce: (inout State, Action) -> Void
  22. var body: Self { self } // ???
  23.  
  24. func reduce(state: inout State, action: Action) {
  25. performReduce(&state, action)
  26. }
  27. }
  28.  
  29. // ERROR: 'Reducer' requires the types 'Action' and '
  30. // (some Reducer).Action' be equivalent
  31. struct EmptyRedcer<State, Action>: Reducer {
  32. var body: some Reducer {
  33. ConcreteReducer<State, Action> { state, action in
  34.  
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement