[Transducer] Lazyness in Transduer
Transducers remove the requirement of being lazy to optimize for things like take(10)
. However, it can still be useful to "bind" a collection to a set of transformations and pass it around, without actually evaluating the transformations.
As noted above, whenever you apply transformations to an iterator it does so lazily. It's easy convert array transformations into a lazy operation, just use the utility function iterator
to grab an iterator of the array instead.
The whole point here is using 'iterator' from transducer.js lib. So you get control when you need the data.
- import t from 'transducers.js';
- const doubleTheNumber = number => number * 2;
- export const evenOnly = number => number % 2 === 0;
- const doubleAndEven = t.compose(
- t.filter(evenOnly),
- t.map(doubleTheNumber),
- );
- const arr = [1,2,3,4,5,6,7,8,9,10];
- const res = t.seq(
- t.iterator(arr),
- t.compose(doubleAndEven, t.take(2)),
- );
- function* makeNumbers() {
- let num = 1;
- while (true) yield num++;
- }
- const lazyNums = t.seq(makeNumbers(), doubleAndEven);
- console.log(
- lazyNums.next(),
- lazyNums.next(),
- lazyNums.next(),
- lazyNums.next(),
- lazyNums.next(),
- lazyNums.next(),
- );
[Transducer] Lazyness in Transduer的更多相关文章
- Scalaz(48)- scalaz-stream: 深入了解-Transducer: Process1-tee-wye
在上一篇讨论里我们介绍了Source,它的类型款式是这样的:Process[F[_],O].Source是通过await函数来产生数据流.await函数款式如下: def await[F[_], A, ...
- [Transducer] Make Transducer works for Iteratable collection and Object
We've seen how we can transduce from arrays or other iterables, but plain objects aren't iterable in ...
- [Transducer] Step by Step to build a simple transducer
Transducers are composable algorithmic transformations. They are independent from the context of the ...
- A Go library implementing an FST (finite state transducer)——mark下
https://github.com/couchbaselabs/vellum Building an FST To build an FST, create a new builder using ...
- [Transducer] Create a Sequence Helper to Transduce Without Changing Collection Types
A frequent use case when transducing is to apply a transformation to items without changing the type ...
- [Transducer] Make an Into Helper to Remove Boilerplate and Simplify our Transduce API
Our transduce function is powerful but requires a lot of boilerplate. It would be nice if we had a w ...
- 翻译连载 | 附录 A:Transducing(下)-《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇
原文地址:Functional-Light-JS 原文作者:Kyle Simpson-<You-Dont-Know-JS>作者 关于译者:这是一个流淌着沪江血液的纯粹工程:认真,是 HTM ...
- WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION
开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...
- ElasticSearch详解与优化设计
简介 概念 安装部署 ES安装 数据索引 索引优化 内存优化 1简介 ElasticSearch(简称ES)是一个分布式.Restful的搜索及分析服务器,设计用于分布式计算:能够达到实时搜索,稳定, ...
随机推荐
- [luogu] P3294 [SCOI2016]背单词 (贪心)
题目描述 Lweb 面对如山的英语单词,陷入了深深的沉思,"我怎么样才能快点学完,然后去玩三国杀呢?".这时候睿智的凤老师从远处飘来,他送给了 Lweb 一本计划册和一大缸泡椒,他 ...
- php安装redis扩展 windows
官方php_redis.dll 找了很久,感谢热心的网友,这是php官方的 php_redis.dll http://windows.php.net/downloads/pecl/releases/r ...
- Java基础学习总结(57)——Jrebel插件热部署
JavaEE开发环境下,Tomcat对热布署的支持还是比较弱,致使开发过程中浪费大量时间在重启服务上.胖先生讨厌来来回回的折腾,所以想看看有没有实时的编译,发现Jrebel的插件付费软件,它对热布署的 ...
- iOS开发- 生成/解析.vcf文件
vcf, 通讯录导出的一种格式. 一.生成vcf文件 假设要把我们iPhone通讯录里的数据, 生成vcf格式文件. 我们能够借助iCloud. 小技巧:通过iCloud导出iPhone通讯录的方法 ...
- vue 结合 echarts
http://blog.csdn.net/mr_wuch/article/details/70225364
- m_Orchestrate learning system---十七、页面美观的关键是什么
m_Orchestrate learning system---十七.页面美观的关键是什么 一.总结 一句话总结:图片用好看的 1.项目板块化? 就是一个个模块,能复用的话很快的 页面由这一个个模块拼 ...
- SVG 贝塞尔曲线控制【方便设置】:贝塞尔曲线
http://dayu.pw/svgcontrol/
- 92.bower 需要git
转自:https://blog.csdn.net/chenleismr/article/details/50458496Bower 是基于 Git 之上的包管理工具,它提供的包其源头都是一个 Git ...
- HD-ACM算法专攻系列(6)——Big Number
题目描述: 源码: #include"iostream" #include"cmath" using namespace std; #define PI 3.1 ...
- Win7 如何禁用“切换用户”功能
1.按win+r,输入gpedit.msc,点击确定: 2.依次点击计算机配置--管理模块--系统--登录,右侧列表中找到“隐藏“快速用户切换”的入口点”: 3.双击隐藏“快速用户切换”的入口点,点击 ...