We rewrite the Box example using lazy evaulation.

Here is Box example:

const Box = (x) => ({
map: f => Box(f(x)),
fold: f => f(x)
}); const res = Box(' 64 ')
.map(abba => abba.trim())
.map(trimmed => new Number(trimmed))
.map(number => number + )
.map(x => String.fromCharCode(x))
.fold(x => x.toLowerCase()); console.log(res); // 'a'

So how to make it as Lazy Box? The Answer is instead of passing a value to the Box, we pass and function into it.

const LazyBox = (fn) => ({
map: g => LazyBox(() => g(fn())),
fold: g => g(fn()) // call the g()
}); const res = LazyBox(() => ' 64 ')
.map(abba => abba.trim())
.map(trimmed => new Number(trimmed))
.map(number => number + )
.map(x => String.fromCharCode(x))
.fold(x => x.toLowerCase()); console.log(res); // 'a'

inside map function, we use function defination:

() => g(fn())

Just defined, but not call. Using g() is to make it composeable.

When actually 'fold', we call fn():

fold: g => g(fn()) // call the g()

One important thing to take away, to make it lazy, wrap into a function

最新文章

  1. Tomcat调优及JMX监控
  2. js017-错误处理与调试
  3. Netbeans 设置模板
  4. [SoapUI] SoapUI JDBC REST 连接 Netezza
  5. 简单的javascript--test2
  6. 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
  7. 【新产品发布】【GK101 10MHz任意波发生器】
  8. ASP.NET MVC5 第4章
  9. mapreduce学习指导及疑难解惑汇总
  10. Msys+MinGW编译VLC
  11. jquery中的globalEval()源码分析
  12. spring jdbcTemplate 事务,各种诡异,包你醍醐灌顶!
  13. 进入jsp页面的6种方法
  14. HDU 5961 传递 随机化
  15. 安装phpssdbadmin
  16. Robotics Tools
  17. easyui---修改删除查询
  18. Spring Boot切换为APR模式
  19. SpringMVC拦截器实现:当用户访问网站资源时,监听session是否过期
  20. 【IntelliJ IDEA】idea上提交代码到GitHub,已经提交了 但是GitHub上却没有的解决办法

热门文章

  1. Sharepoint 2010 TimerJob重复
  2. Python并发编程-守护进程
  3. socket的使用二
  4. codevs 1102 采药 2005年NOIP全国联赛普及组
  5. [BZOJ3203][SDOI2013]保护出题人(凸包+三分)
  6. pat 打印沙漏
  7. WNDR4300v2 固件编译
  8. SCOJ 4429: frog's dice 最大流
  9. PYPY_GC
  10. Windows xp/2003 中安装虚拟网卡 Microsoft Loopback Adapter