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

[Compose] 9. Delay Evaluation with LazyBox的更多相关文章

  1. Java性能提示(全)

    http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...

  2. Swift的闭包(二):捕获值

    闭包可以从定义它的上下文中捕获常量和变量. 在Swift中,捕获值最简单的例子是嵌套函数,举个例子: func makeIncrementer(forIncrement amount: Int) -& ...

  3. R2—《R in Nutshell》 读书笔记(连载)

    R in Nutshell 前言 例子(nutshell包) 本书中的例子包括在nutshell的R包中,使用数据,需加载nutshell包 install.packages("nutshe ...

  4. Overview and Evaluation of Bluetooth Low Energy: An Emerging Low-Power Wireless Technology

    转自:http://www.mdpi.com/1424-8220/12/9/11734/htm Sensors 2012, 12(9), 11734-11753; doi:10.3390/s12091 ...

  5. 【原创翻译】Reducing Branch Delay to Zero in Pipelined Processors

    在流水线处理器中减少分支延迟到零 Antonio M. Gonzalez and Jose M. Llaberia 摘要 一种减少流水处理器中分支延迟到零的机制将在本文被描述以及评估.这种机制基于多重 ...

  6. Docker 小记 — Compose & Swarm

    前言 任何相对完整的应用服务都不可能是由单一的程序来完成支持,计划使用 Docker 来部署的服务更是如此.大型服务需要进行拆分,形成微服务集群方能增强其稳定性和可维护性.本篇随笔将对 Docker ...

  7. Docker Compose 配置文件常用指令

    Docker Compose 配置文件常用指令 YAML文件格式及编写注意事项 YAML是一种标记语言很直观的数据序列化格式,可读性高.类似于XML数据描述语言,语法比XML简单的很多. YAML数据 ...

  8. 附005.Docker Compose文件详解

    一 Docker Compose文件简介 compose文件使用yml格式,主要分为了四个区域: version:用于指定当前docker-compose.yml语法遵循哪个版本 services:服 ...

  9. 基音检测算法的性能:Performance Evaluation of Pitch Detection Algorithms

    http://access.feld.cvut.cz/view.php?cisloclanku=2009060001 Vydáno dne 02. 06. 2009 (15123 přečtení) ...

随机推荐

  1. Centos7 安装单节点Torque PBS

    Operation system: CentOS 7.3 Torque PBS: torque-6.1.1.1.tar hostname: rfmlab user name: cfd01 1. Ins ...

  2. C#多线程编程实战(一):线程基础

    1.1 简介 为了防止一个应用程序控制CPU而导致其他应用程序和操作系统本身永远被挂起这一可能情况,操作系统不得不使用某种方式将物理计算分割为一些虚拟的进程,并给予每个执行程序一定量的计算能力.此外操 ...

  3. 修复mysql

    REPAIR TABLE TABLENAME 或 REPAIR TABLE TABLENAME USE_FRM

  4. C和指针之学习笔记(1)

    第1章 1.输入字符串 while((ch=getchar())!=EOF  &&  ch!=’\n’) ; ch=getchar() while(ch!=EOF  && ...

  5. UESTC 1330 柱爷与远古法阵【高斯消元】

    题目链接[http://acm.uestc.edu.cn/#/problem/show/1330] 题意:有一个长度为L(L <= 300)的长廊,有一人站在最左边,他要到最右边去,他每次可以走 ...

  6. 安卓 onTouch OnTouchEvent onChick 顺序

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 分发触摸事件 -> 在 触摸 时候 -> 在触摸事件时候->在点击时候 ...

  7. CXF和Axis2的区别

    1.CXF支持 WS-Addressing,WS-Policy, WS-RM, WS-Security和WS-I Basic Profile.Axis2不支持WS-Policy,但是承诺在下面的版本支 ...

  8. Boost汉字匹配 -- 宽字符

      原文链接:http://blog.csdn.net/sptoor/article/details/4930069 思路:汉字匹配,把字符都转换成宽字符,然后再匹配. 需要用到以下和宽字符有关的类: ...

  9. 实战DELPHI:远程线程插入(DLL注入)

    http://www.jx19.com/xxzl/Delphi/2010/04/17/ShiZhanDELPHI_YuanChengXianChengChaRu_DLLZhuRu/ 远程注入DLL方法 ...

  10. Druid 配置_配置WebStatFilter

    https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_%E9%85%8D%E7%BD%AEWebStatFilter WebStatFilt ...