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的更多相关文章

  1. 技能UP:SAP CO掌上配置手册

    No. 配置对象 事务代码 路径 1 Enterprise Structure and General Controlling configration       Maintain EC-PCA : ...

  2. 《MySQL数据操作与查询》- 综合项目 - 学生管理系统

    <MySQL数据操作与查询>综合项目需求 一.系统整体功能 维护学生信息.老师信息和成绩信息. 支持按多种条件组合查询学生信息和成绩信息. 二.系统的信息需求 一个班级有一个讲师一个班主任 ...

  3. 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 ...

  4. [MySQL Reference Manual] 18 复制

    18 复制 18 复制 18.1 复制配置 18.1.1 基于Binary Log的数据库复制配置 18.1.2 配置基于Binary log的复制 18.1.2.1 设置复制master的配置 18 ...

  5. Mesh Data Structure in OpenCascade

    Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...

  6. [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 ...

  7. Think Python - Chapter 18 - Inheritance

    In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...

  8. highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏

    /*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...

  9. Hierarchical Storage structure

    1.hierarchical storage structure      This notion of inserting a smaller, faster storage device (e.g ...

随机推荐

  1. 76.CGI编码

    CGI编码 "%D6%DC%C8%F0%B8%A3"; 转换到字符串中: //CGI编码转到char类型的tmpstr中中 char* change(char *str) { // ...

  2. golang sync.Mutex(2)

    package main import ( "fmt" "sync" "time" ) type User struct { Name st ...

  3. InstallShield详细制作说明(三)

    八.许可协议 打开[Installation Designer]->[Behavior and Logic]->[Support Files/Billboards]面板 这里[Langua ...

  4. eclipse git冲突解决

    1.工程->Team->同步: 2.从远程pull至本地,就会出现如下内容: 3.使用Merge Tool,执行第二项 4.再手动修改 4.修改后的文件需要添加到Git index中去: ...

  5. [Javascript] Iterate Over Items with JavaScript's for-of Loop

    In this lesson we will understand the For Of loop in Javascript which was introduced in ES6. The for ...

  6. amazeui学习笔记一(开始使用4)--Web App 相关

    amazeui学习笔记一(开始使用4)--Web App 相关 一.总结 1.桌面图标(Touch icon)解决方案:终极方案:link标签的rel和href属性: <link rel=&qu ...

  7. Linux体系结构

    linux内核结构: system call interface (SCI层) 为用户空间提供了一套标准的系统调用函数来访问linux内核. process management (PM层) 进程管理 ...

  8. vue 星星评分组件

    显示评分和打分组件,可现实半颗星星效果 效果图: 参数名 类型 说明 score Number 分数 ,默认0,保留一位小数 disabled Boolean 是否只读,默认false,鼠标点击可以打 ...

  9. Injection of autowired dependencies failed; autowire 自动注入失败,测试类已初始化过了Spring容器。

    1 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creat ...

  10. 01011_怎么打开任务管理器?win7打开任务管理器方法

    以下几种方法可以打开任务管理器 1.在系统的任务栏点击鼠标右键,然后在弹出的右键菜单中选择“启动任务管理器”: 2.同时按下这三个按钮:Ctrl + Shift + Esc: 3.同时按下键盘的Ctr ...