[Compose] 9. Delay Evaluation with LazyBox
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的更多相关文章
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- Swift的闭包(二):捕获值
闭包可以从定义它的上下文中捕获常量和变量. 在Swift中,捕获值最简单的例子是嵌套函数,举个例子: func makeIncrementer(forIncrement amount: Int) -& ...
- R2—《R in Nutshell》 读书笔记(连载)
R in Nutshell 前言 例子(nutshell包) 本书中的例子包括在nutshell的R包中,使用数据,需加载nutshell包 install.packages("nutshe ...
- 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 ...
- 【原创翻译】Reducing Branch Delay to Zero in Pipelined Processors
在流水线处理器中减少分支延迟到零 Antonio M. Gonzalez and Jose M. Llaberia 摘要 一种减少流水处理器中分支延迟到零的机制将在本文被描述以及评估.这种机制基于多重 ...
- Docker 小记 — Compose & Swarm
前言 任何相对完整的应用服务都不可能是由单一的程序来完成支持,计划使用 Docker 来部署的服务更是如此.大型服务需要进行拆分,形成微服务集群方能增强其稳定性和可维护性.本篇随笔将对 Docker ...
- Docker Compose 配置文件常用指令
Docker Compose 配置文件常用指令 YAML文件格式及编写注意事项 YAML是一种标记语言很直观的数据序列化格式,可读性高.类似于XML数据描述语言,语法比XML简单的很多. YAML数据 ...
- 附005.Docker Compose文件详解
一 Docker Compose文件简介 compose文件使用yml格式,主要分为了四个区域: version:用于指定当前docker-compose.yml语法遵循哪个版本 services:服 ...
- 基音检测算法的性能: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í) ...
随机推荐
- 关于字体剥离和精简工具 FontSubsetGUI 和 FontPruner 的比较。
在 Unity 中制作游戏时对动态字体的剥离和精简是现在常用的手段,现在有两篇博客是大家阅读和参照较多的,分别是 如何精简Unity中使用的字体文件 和 FontPruner 字体精简工具.他们各自提 ...
- POJ1226 Substrings
后缀数组. 求多个字符串翻转与否中最长公共子串长. 二分答案,反过来多建一倍的字符串,二分时特判一下即可. By:大奕哥 #include<cstring> #include<cst ...
- Codeforces 992 E. Nastya and King-Shamans
\(>Codeforces\space992 E. Nastya and King-Shamans<\) 题目大意 : 给你一个长度为 \(n\) 的序列,有 \(q\) 次操作,每一次操 ...
- 是否排序好了 Exercise07_19
import java.util.Scanner; import java.util.Arrays; /** * @author 冰樱梦 * 时间2018年12月 * 题目:是否排序好了 * */ p ...
- Codeforces Beta Round #80 (Div. 1 Only) D. Time to Raid Cowavans 分块
D. Turtles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/103/problem/D ...
- 关于GCC Cygwin MinGW MSYS
[转载]关于Gcc/MinGW/Cygwin/Msys http://blog.sciencenet.cn/blog-778757-616920.html 一.GCC的历史 GCC是一个原本用于Uni ...
- switch语句的基本使用
switch是一个多分支的选择语句. 1.基本格式: switch(整型表达式){ case 整型字面量: ...... default : } 解释: 1)整型字面量可 ...
- gdb 与函数过程
http://www.lenky.info/archives/2013/02/2202
- 搭建windows server 2008 r2 FTP 后 开启防火墙无法访问的解决办法
转自http://kkworms.blog.51cto.com/540865/558477 今天在windows server 2008 R2上安装了FTP,安装过程如下,然后添加内置防火墙设置,设置 ...
- InstallShield 2010集成.net Framework 4的安装包制作
InstallShield 2010中制作安装包时,对于集成.net Framework 4以前的版本,如3.5 sp1/3.5/3.0/2.0 sp2/2.0sp1/2.0等提供了现成的prq文件模 ...