[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 flip
combinator 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 ...
随机推荐
- C#读取RSS源,并利用Solr索引
折磨我几天的问题今天终于解决了,分享一下近期solr使用的一些经验. 本来是用nutch在爬取页面,可是客户需要爬取RSS,而且可以识别那些页面是通过RSS源抓取出来的.nutch虽然自带解析RSS的 ...
- 开源地图编辑器 MarbleMap,支持Cocos2d-x坐标系
由9秒社团开发并维护的MarbleMap是支持Cocos2d-x坐标系和as3坐标系的地图编辑器,功能完善高效.这里详细介绍一下它的使用方法! 一.功能简述 由9秒社团开发并维护的MarbleMap是 ...
- 关于DRY原则
软件工程,模式,语言,设计思想发展到今天,说白了,所有的技巧,思想,原则归根结底都是为了这个DRY 从机器语言开始: 为了DRY,出现了汇编符号来代表指令,使开发人员不用“重复翻阅指令手册” 为了D ...
- HDU 4863 Centroid of a Tree
树的重心,树形$dp$,背包. 树的重心有两个充分必要条件: $1$.某树有两个重心$a$,$b$ $<=>$ $a$与$b$相邻,断开$a$与$b$之间的边之后,两个联通分量内的点的个数 ...
- CNN的发展
模型的建立过程: 1959年,Hubel & Wiesel发现动物视觉皮层中的细胞负责检测感受野(receptive fields)中的光线.论文:Receptive fields and f ...
- 34、Flask实战第34天:修改邮箱
修改邮箱页面布局 新建cms/cms_resetemail.html {% extends 'cms/cms_base.html' %} {% block title %}修改邮箱-CMS管理系统{% ...
- EasyUI学习总结(六)——EasyUI布局(转载)
本文转载自:http://www.cnblogs.com/xdp-gacl/p/4088198.html 一.EasyUI布局介绍 easyUI布局容器包括东.西.南.北.中五个区域,其中中心面板是必 ...
- 【BZOJ 2878】 2878: [Noi2012]迷失游乐园 (环套树、树形概率DP)
2878: [Noi2012]迷失游乐园 Description 放假了,小Z觉得呆在家里特别无聊,于是决定一个人去游乐园玩.进入游乐园后,小Z看了看游乐园的地图,发现可以将游乐园抽象成有n个景点.m ...
- [BZOJ 2668] 交换棋子
Link: BZOJ 2668 传送门 Solution: 重点在于对于每条转移路径:首尾算一次,中间节点算两次 可以一点拆三点,将原流量拆成入流量和出流量 但其实也可以就拆两点,分前后是否是一首尾点 ...
- 【树形dp】Apple Tree
[poj2486]Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10800 Accepted: 3 ...