The true power of the State ADT really shows when we start combining our discrete, stateful transactions. We start looking at another construction helper named of, used to lift any given value of any type into the resultant. We also explore another instance method called chain that is used for combining our simple, discrete transactions into more complex flows that can be extended to meet our needs as they arise. To create a set of stateful transactions to be combined, we see how the get and modify construction helpers can be used to make simple, easy to read code.

const { constant, Pair, Unit, curry, objOf, compose, State, mapProps, prop, option } = require("crocks");

const { put, get, modify } = State;

const add = x => y => x+y;
const inc = add(); // State s a -> State(x => Pair(a, x)) // 'get' return result apply to variable a
const addState = n =>
get(add(n)) const incState = n =>
modify(inc) // modify return Unit() in variable position, Pair( (), 3 )
.map(constant(n)) // to keep the vairable a, we can use constant to wrap a value into function, Pair( 12, 3 ) const compute = n =>
State.of(n)
.chain(addState)
.chain(incState) console.log(
compute()
.runWith()
)

最新文章

  1. 使用 jQuery 和 CSS3 制作滑动导航菜单
  2. JS魔法堂:再次认识Function.prototype.call
  3. IE盒模型
  4. Django1.9开发博客(9)- 用户认证
  5. JS图片加载失败显示默认图片
  6. 暑假集训(4)第三弹 -----递推(Hdu1799)
  7. google yeoman
  8. linq里的select和selectmany操作 投影运算
  9. Android开发Thread+Handler演示样本(打地鼠)
  10. C# WebBrowser 代理的使用
  11. Android灯光系统--深入理解背光灯
  12. 【bird-java】bird-java概述
  13. BZOJ 3450: Tyvj1952 Easy [DP 概率]
  14. 微信小程序入门(五)
  15. [SP1043] GSS1 - Can you answer these queries I
  16. Apigee 简介与简单试用
  17. 【配置】log4j.properties 详解与配置步骤
  18. android 获取sd卡根目录
  19. windows下docker的安装并使用
  20. thinkphp模型创建

热门文章

  1. section
  2. Mybatis框架-2
  3. Java网络编程一
  4. 使用supervisor管理后台进程
  5. leetcode155 Min Stack
  6. Failure INSTALL FAILED DUPLICATE PERMISSION
  7. 数据库SQL归纳(二)
  8. 【暴力】hdu6121 Build a tree
  9. 【DFS】POJ3009-Curling 2.0
  10. Java学习笔记(16)