[Javascript] Broadcaster + Operator + Listener pattern -- 11. Customize the done logic
JavaScript -- The 11 pattern Operator listener Logic
2023-09-14 09:00:46 时间
Buffers give you chance to gather values together until your ready to work with them. This pattern can be used for calculations, string manipulations, and many other scenarios.
Consider a solution where splitter argument is a function instead of a value. How could you capture the condition in that function rather than the way it was implemented in this lesson
Sometime if "createOpertor"'s done logic is not actully what you want, when you can customize you own done logic:
const split = splitter => curry((broadcaster, listener) => { let buffer = [] return broadcaster((value) => { if (value === done) { // emit the rest of buffer on done listener(buffer) listener(done) buffer = [] } if (value === splitter) { listener(buffer) buffer = [] } else { buffer.push(value) } }) })
Usage:
const transform = pipe( map((x) => x[1]), filter((x) => x !== ','), map(toUpper), split(" ") ); let typeGreeting = transform( createZipOf(createInterval(100), createForOf('My Zipo')) ); const cancelGreating = typeGreeting((value => { if(value === done) { _log("Shut down") return } _log(value) }))
相关文章
- javascript中正则表达式和ruby中的一点差异
- Javascript之旅——第十一站:原型也不好理解?
- 第一百六十一节,封装库--JavaScript,完整封装库文件
- 第一百五十三节,封装库--JavaScript,表单验证--备注字数验证
- 第一百三十五节,JavaScript,封装库--拖拽
- 第一百三十一节,JavaScript,封装库--CSS
- JavaScript -- 正则表达式
- [Javascript] Broadcaster + Operator + Listener pattern -- 11. Customize the done logic
- JavaScript -- throw、try 和 catch
- [Javascript] Broadcaster + Operator + Listener pattern -- 3 Stop with condition
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part5
- [Testing] Config jest to test Javascript Application -- Part 2
- [Javascript] Linting JavaScript with ESLint
- UglifyJS--javascript代码压缩使用指南{转}
- 运行在生产系统中的企业级 JavaScript 应用的性能问题分析指南
- 分享一个开源的JavaScript统计图表库,40行代码实现专业统计图表
- 学习Javascript闭包(Closure)
- Javascript 学习 笔记六
- Atitit.javascript 实现类的方式原理大总结
- javascript--枚举算法实现