[Functional Programming ADT] Combine Multiple State ADT Based Redux Reducers
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的更多相关文章
- [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 ...
- [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 ...
- [Functional Programming Monad] Combine Stateful Computations Using Composition
We explore a means to represent the combination of our stateful computations using familiar composit ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- Python基础系列----环境的搭建及简单输入、输出
1.Python 以下信 ...
- nodejs调试基础【转载】
nodejs调试基础[转载] 看到了一片不错的文章: 作者:前端求生之路 链接:nodejs调试基础[转载]
- CentOS7.5安装notepadqq
这个notepadqq就是linux版本的notepad了 1.添加yum源 sudo wget -O /etc/yum.repos.d/sea-devel.repo http://sea.fedor ...
- Win7 + VirtualBox + CentOS(无桌面), 扩容
http://www.2cto.com/os/201401/269730.html 对于目前的网络开发者来说,比较好的搭档就是Win7+VirtualBox+CentOS的组合,既可以发挥Linux强 ...
- 【Tempest】openstack自动化测试组件tempest及自动化测试工具nose
宝宝心里苦,但是宝宝只能在这穷乡僻壤说,下周又要开组会必须得干点事了.这次是做论文中的实验部分,主要利用到了openstack中的自动化测试组件Tempest,具体原因不细说了. 安装 分两种安装方法 ...
- 设计模式-命令模式(Command Pattern)
本文由@呆代待殆原创,转载请注明出处:http://www.cnblogs.com/coffeeSS/ 命令模式简述 命令模式的主要作用是将“行为请求者”和“行为实现者”解耦.举个例子,假如我们现在要 ...
- MTK平台源码 mt6589-jb3-x_20131122
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha
- [BZOJ1913][APIO2010]信号覆盖(计算几何+计数)
1913: [Apio2010]signaling 信号覆盖 Time Limit: 20 Sec Memory Limit: 64 MBSubmit: 1658 Solved: 672[Subm ...
- 【贪心】【堆】bzoj2590 [Usaco2012 Feb]Cow Coupons
每个物品有属性a,b 考虑在仅仅用光优惠券时的最优方案. 显然是按照b排序,取前K个. 但是我们还要尽可能去取剩余的. 假设朴素地取剩余的话,应该把剩余的对a排序,然后尽量去取. 但是有可能对其用优惠 ...
- 【高斯消元解xor方程组】BZOJ2466-[中山市选2009]树
[题目大意] 给出一棵树,初始状态均为0,每反转一个节点的状态,相邻的节点(父亲或儿子)也会反转,问要使状态均为1,至少操作几次? [思路] 一场大暴雨即将来临,白昼恍如黑夜!happy! 和POJ1 ...