ethul / purescript-react-redux

MIT License
15 stars 6 forks source link

Potentially move to another module #12

Open ethul opened 7 years ago

ethul commented 7 years ago
reducerOptic :: forall state state' action action'. Lens' state state' -> Prism' action action' -> Reducer' action' state' -> Reducer' action state
reducerOptic lens prism k =
  wrap $ \action state ->
    let
      state' :: state'
      state' = view lens state

      action' :: Either action action'
      action' = matching prism action

    in either (const state) (\a -> set lens (unwrap k a state') state) action'