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. MockServer jar包安装

    github地址: https://github.com/jamesdbloom/mockserver 1. org.apache.maven.plugin-tools:maven-plugin-an ...

  2. 通过Ajax进行POST提交JSON类型的数据到SpringMVC Controller的方法

    现在在做的项目用到了SpringMVC框架,需要从前端angular接收请求的JSON数据,为了测试方便,所以直接先用AJAX进行测试,不过刚开始用平时用的ajax方法,提交请求会出现415或者400 ...

  3. POJ1308——Is It A Tree?

    Is It A Tree? Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22631   Accepted: 7756 De ...

  4. Flume Channels官网剖析(博主推荐)

    不多说,直接上干货! Flume Sources官网剖析(博主推荐) 一切来源于flume官网 http://flume.apache.org/FlumeUserGuide.html Flume Ch ...

  5. css 0.5px

    1. 利用css3新属性scale(好用推荐) 其实现的关键就是利用before或after伪元素,宽高同时设为200%,然后再缩放0.5,自然就是0.5px了 代码如下: div { positon ...

  6. win10系统64位安装git后右键运行git bash here生成一个mintty.exe.stackdump文件后闪退解决方案

    在其他win10电脑上复制了一个null.sys文件,替换C:\Windows\System32\drivers\null.sys,搞定.

  7. Cocos2d-x学习笔记(一)HelloWorld

    原创文章,转载请注明出处:http://blog.csdn.net/sfh366958228/article/details/38656755 前言 正式来公司实习已有一月,前一月主要是看了<C ...

  8. 使用VHD,让Win XP和 Win2003 运行在内存中

    通过一定的手段可以让XP和2003甚至Win7运行在内存中.我很感兴趣,于是按照网上的资料在VBox虚拟机中测试了一次,运行成功.这几天将其折腾到实体机上. 声明:我的做法和网上的做法有些不一样,我的 ...

  9. JQ的核心原理以及扩展等

    jQuery核心原理 定义原型扩展和工具包扩展的方法 JQ的API中文速查: http://jquery.cuishifeng.cn/ JQ的原理:http://www.cnblogs.com/Sca ...

  10. [Angular] Component architecture and Reactive Forms

    It it recommeded that when deals with form component, we can create a container component to hold st ...