[Compose] 18. Maintaining structure whilst asyncing
We take our Promise.all() analogy further by using traversable on a Map(). Then we use two traversals in the same workflow.
Traverse is good for maintaning the original data structure:
const Task          = require('data.task');
const { List, Map } = require('immutable-ext');
const httpGet = (path, params) => Task.of(`${path} result`);
// map
const res0 = Map(
    {
        home  : '/',
        about : '/about'
    }
).map(route =>
        httpGet(route, {})
);
console.log(res0); // Map{ home: Task(), about: Task()}
For example, the code here return Map({Task}) instead of Map({}).
So we can actually replace map with traverse.
// Traverse
Map(
{
home: '/',
about: '/about'
}
).traverse(
Task.of,
route => httpGet(route, {})
).fork(console.error, console.log); // Map { "home": "/ result", "about": "/about result" }
Now we are able to keep the same structure as before.
We can also use double traverse if needed, for example we change data to array of path inside of string:
// Double traverse
Map(
{
home: ['/', '/home'],
about: ['/about', '/help']
}
).traverse(
Task.of,
routes =>
List(routes)
.traverse(
Task.of,
route => httpGet(route, {})
)
).fork(
console.error, console.log
); // Map { "home": List [ "/ result", "/home result" ], "about": List [ "/about result", "/help result" ] }
Because Array doesn't have traverse function, so we need to use List from immutable.
[Compose] 18. Maintaining structure whilst asyncing的更多相关文章
- 技能UP:SAP CO掌上配置手册
		No. 配置对象 事务代码 路径 1 Enterprise Structure and General Controlling configration Maintain EC-PCA : ... 
- 《MySQL数据操作与查询》- 综合项目 - 学生管理系统
		<MySQL数据操作与查询>综合项目需求 一.系统整体功能 维护学生信息.老师信息和成绩信息. 支持按多种条件组合查询学生信息和成绩信息. 二.系统的信息需求 一个班级有一个讲师一个班主任 ... 
- deepin 15.11 升级docker-ce 18.01到19.03.1,升级docker compose 1.23到1.24.1
		1.升级docker compose ,docker官方安装方法 $ sudo curl -L "https://github.com/docker/compose/releases/dow ... 
- [MySQL Reference Manual] 18 复制
		18 复制 18 复制 18.1 复制配置 18.1.1 基于Binary Log的数据库复制配置 18.1.2 配置基于Binary log的复制 18.1.2.1 设置复制master的配置 18 ... 
- Mesh Data Structure in OpenCascade
		Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ... 
- [CareerCup] 18.8 Search String 搜索字符串
		18.8 Given a string s and an array of smaller strings T, design a method to search s for each small ... 
- Think Python - Chapter 18 - Inheritance
		In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ... 
- highgui.h备查                                                    分类:            C/C++             OpenCV             2014-11-08 18:11    292人阅读    评论(0)    收藏
		/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ... 
- Hierarchical Storage structure
		1.hierarchical storage structure This notion of inserting a smaller, faster storage device (e.g ... 
随机推荐
- (转)Tomcat调优
			问题定位 对于Tomcat的处理耗时较长的问题主要有当时的并发量.session数.内存及内存的回收等几个方面造成的.出现问题之后就要进行分析了. 1.关于Tomcat的session数目 这个可以直 ... 
- 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers
			[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两 ... 
- COGS——T 2057. [ZLXOI2015]殉国
			http://cogs.pro/cogs/problem/problem.php?pid=2057 ★☆ 输入文件:BlackHawk.in 输出文件:BlackHawk.out 评测插件 ... 
- 关于C++中的内存泄露
			1.c++内存泄漏的定义: 内存泄漏(memory leak)是指由于疏忽或错误造成了程序未能释放掉不再使用的内存的情况.内存泄漏并非指内存在物理上的消失,而是应用程序分配某段内存后,由于设计错误,失 ... 
- 11G、12C Data Guard Physical Standby Switchover转换参考手册
			Switchover转换 Step 1: switchover 切换先前检查 (1)确保主备两端log_archive_config和db_unique_name参数都已经正确设置. 需要注意的是 ... 
- Appium_Java_API
			1. driver.findElement(MobileBy.AndroidUIAutomator("邀请")).click();2. driver.findElementById ... 
- 【Codeforces Round #431 (Div. 2) A】Odds and Ends
			[链接]点击打开链接 [题意] 让你把一个数组分成奇数个部分. 且每个部分的长度都是奇数. [题解] 很简单的脑洞题. 开头和结尾一定要为奇数,然后 n为奇数的话,就选整个数组咯. n为偶数的话,不能 ... 
- Traveler Nobita (zoj 3456 最小生成树)
			Traveler Nobita Time Limit: 2 Seconds Memory Limit: 65536 KB One day, Nobita used a time machin ... 
- Android Material风格的应用(五)--CollapsingToolbar
			Collapsing Toolbar Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--RecyclerViewA ... 
- 从大整数乘法的实现到 Karatsuba 快速算法
			Karatsuba 快速乘积算法是具有独特合并过程(combine/merge)的分治算法(Karatsuba 是俄罗斯人).此算法主要是对两个整数进行相乘,并不适用于低位数(如 int 的 32 位 ... 
