Using put to update our state for a given state transaction can make it difficult to modify a given state based on its previous value. In this lesson we will explore a means to lift specialized functions that can be used modify our state’s value. These specialized functions must have the same type in their input and output. We take a look at a construction helper named modify that is used to remove the boilerplate of this type of construction. We also start to see how we can extend simple discrete stateful transactions to create other stateful transactions.

Modify state is apply a function to the original state to get new state:

// modifyState :: (s -> s) -> State s ()
const modifyState = fn => State(s => Pair(Unit(), fn(s)));
// modifyState :: (s -> s) -> State s ()
const modifyState = fn => State(s => Pair(Unit(), fn(s)));
const bubble = {
bubbles:
};
const add = x => y => x+ y;
console.log(
modifyState(mapProps({bubbles: add()}))
.runWith(bubble) // Pair( (), { bubbles: 41 } )
)

Of couse, we have the 'modify' function already in the library, so the code can be changed to:

const bubble = {
bubbles:
};
const add = x => y => x+ y;
console.log(
modify(mapProps({bubbles: add()}))
.runWith(bubble) // Pair( (), { bubbles: 41 } )
)

最新文章

  1. [2016.01.22]万峰文本处理专家 v2.1
  2. IO-01. 表格输出(5)
  3. C语言文件方式输入与输出(最简洁方便实用的一种方式)
  4. [Effective JavaScript 笔记]第65条:不要在计算时阻塞事件队列
  5. 简单介绍.Net3.0 中跨线程访问控件
  6. Spring(五)AOP简述
  7. oracle sql语言模糊查询--通配符like的使用教程
  8. VS2013 不能打开DTCMS项目 的解决办法
  9. CQRS学习——Cqrs补丁,async实验以及实现[其二]
  10. 软碟通UltraISO 9.65.3237官方注册版
  11. CSAPP 六个重要的实验 lab5
  12. Swift 3.0 字符串、数组、字典的使用
  13. SQL Server删除表信息的三种方法
  14. Java基础---Java---正则表达式-----匹配、切割、替换、获取等方法
  15. javascript的隐式类型转换
  16. 在Ubuntu 12.04下创建eclipse的桌面链接
  17. python 将文件描述符包装成文件对象
  18. SDN 第三次上机作业
  19. 【Shell】Linux的判断表达式:-d,-f,-e等
  20. javascript开发HTML5游戏--斗地主(单机模式part2)

热门文章

  1. Java Control Statements
  2. css文本、字母、数字过长 自动换行处理
  3. redis的运行机制
  4. Sqli-labs less 4
  5. 写的模块和方法 wap 和 pc
  6. bzoj 2038 小Z的袜子(hose)(莫队算法)
  7. 【状压dp】Travelling
  8. [BZOJ2595]游览计划
  9. python基础之类与对象,继承与派生
  10. Problem C: 零起点学算法93——矩阵转置