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
)
);

[Functional Programming ADT] Combine Multiple State ADT Based Redux Reducers的更多相关文章

  1. [Functional Programming] Combine Multiple State ADT Instances with the Same Input (converge(liftA2(constant)))

    When combining multiple State ADT instances that depend on the same input, using chain can become qu ...

  2. [Functional Programming Monad] Combine Stateful Computations Using A State Monad

    The true power of the State ADT really shows when we start combining our discrete, stateful transact ...

  3. [Functional Programming Monad] Combine Stateful Computations Using Composition

    We explore a means to represent the combination of our stateful computations using familiar composit ...

  4. [Functional Programming Monad] Modify The State Of A State Monad

    Using put to update our state for a given state transaction can make it difficult to modify a given ...

  5. [Functional Programming Moand] Update The State Of A State Monad (put)

    Stateful computations require the ability for their state to change overtime. We take a look on one ...

  6. [Functional Programming] Combine State Dependent Transactions with the State ADT (composeK to replace multi chian call)

    When developing a Finite State Machine, it is often necessary to apply multiple transitions in tande ...

  7. [React + Functional Programming ADT] Connect State ADT Based Redux Actions to a React Application

    With our Redux implementation lousy with State ADT based reducers, it is time to hook it all up to a ...

  8. [Functional Programming ADT] Create a Redux Store for Use with a State ADT Based Reducer

    With a well defined demarcation point between Redux and our State ADT based model, hooking up to a R ...

  9. [Functional Programming ADT] Create State ADT Based Reducers (applyTo, Maybe)

    The typical Redux Reducer is function that takes in the previous state and an action and uses a swit ...

随机推荐

  1. ELK系列--justniffer0.5.12安装报错解决方法

    现象: justniffer的0.5.12(安装后显示0.5.13版本)安装过程中需要升级boost至1.46以上版本,同时在make时会出现如下报错: /opt/Python-2.6.6/Pytho ...

  2. bzoj 1040 基向内环树dp

    #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk mak ...

  3. 【剑指offer】面试题 57. 和为 S 的数字

    面试题 57. 和为 S 的两个数字 题目一:和为 S 的两个数字 题目 输入一个递增排序的数组和一个数字 S,在数组中查找两个数,是的他们的和正好是 S,如果有多对数字的和等于 S, 输出两个数的乘 ...

  4. ZOJ 3279-Ants(线段树)

    传送门:zoj 3279 Ants Ants Time Limit: 2 Seconds      Memory Limit: 32768 KB echo is a curious and cleve ...

  5. CodeForces 740D Alyona and a tree

    倍增,延迟标记. 考虑一个$u$给他的哪几个祖先$v$贡献了$1$.越往上$dis(v,u)$越大,找到最远的一个还满足条件的$v$,$v$到$u$的父亲这条链上的答案都$+1$.延迟标记一下,然后从 ...

  6. Java 对象池实现

    http://blog.csdn.net/bryantd/article/details/1100019 http://www.cnblogs.com/devinzhang/archive/2012/ ...

  7. noip2012开车旅行 题解

    题目大意: 给出n个排成一行的城市,每个城市有一个不同的海拔.定义两个城市间的距离等于他们的高度差的绝对值,且绝对值相等的时候海拔低的距离近.有两个人轮流开车,从左往右走.A每次都选最近的,B每次都选 ...

  8. [BZOJ4822][CQOI2017]老C的任务(扫描线+树状数组)

    4822: [Cqoi2017]老C的任务 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 379  Solved: 203[Submit][Statu ...

  9. ARC-100 C - Linear Approximation

    题面在这里! 可以看成点集{a[i]-i}和b之间距离的和,于是找到中位数就可以直接算了2333. #include<bits/stdc++.h> #define ll long long ...

  10. 【LIS】【递推】Gym - 101246H - ``North-East''

    x坐标排序,y坐标当权值,同一个x坐标的,y从大到小排. 求f(i)表示以i结尾的LIS以后,从后向前枚举,不断更新一个max数组,max(i)代表最长上升子序列为i时,当前的 结尾的最大值是多少. ...