加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

[Functional Programming ADT] Combine Multiple State ADT Base

发布时间:2020-12-14 04:25:42 所属栏目:大数据 来源:网络整理
导读:Redux provides a convenient helper for combining many reducers called? combineReducer ,but it focuses in on specific attributes on our state,making it incompatible with using the State ADT. We would like a way to avoid keeping all of our r

Redux provides a convenient helper for combining many reducers called?combineReducer,but it focuses in on specific attributes on our state,making it incompatible with using the State ADT. We would like a way to avoid keeping all of our reducers in a single file and want the ability to still combine them in a manner that works with the?State?ADT.

So we will put together our own helper that we also call?combineReducers,but explore how we can use the?First?Monoid and?mreduceMap?to get us all the power that the Redux helper provides,but setup for our unique needs. As a bonus we will get a sneak peak of the power of using the?flipcombinator to create easy to read compositions without pesky argument juggling

?

// combineReducers :: [ Reducer ] -> Reducer
/*
export const combineReducers = reducers => action =>
  mreduceMap(First,applyTo(action),reducers);
*/
// We take reducers first and action second,but we use action first,reducers second.
// It is good case to use flip
/*
export const combineReducers = flip(action =>
  mreduceMap(First,applyTo(action))
);*/

// We can use compose to remove action param,applyTo will get action
// Then the return result will be passed into mreduceMap(First)
export const combineReducers = flip(
  compose(
    mreduceMap(First),applyTo
  )
);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读