[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 ...
随机推荐
- node --进行后台的环境搭建
1.下载winscp --- 输入IP 端口 账号 密码 进入当前的服务器环境 2.下载xshell5 ---- 输入IP 端口 和 winscp 达成连接. 3.把本地代码放置 winscp远 ...
- RecyclerView 展示多种类型Item数据
一.多Item布局实现(MultipleItem) 如果之前你用过ListView实现过此功能,那么你一定对下面这两个方法并不陌生 @Override public int getItemViewTy ...
- .NET Entity Framework入门操作
Entity Framework是微软借鉴ORM思想开发自己的一个ORM框架. ORM就是将数据库表与实体对象(相当于三层中的Model类)相互映射的一种思想. 最大的优点就是非常方便的跨数据库平台. ...
- Manning.EJB.3.in.Action.2nd.Edition
Manning.EJB.3.in.Action.2nd.Edition http://files.cnblogs.com/files/rojas/EJB_3_in_Action_2nd_Edition ...
- bzoj3307雨天的尾巴(权值线段树合并/DSU on tree)
题目大意: 一颗树,想要在树链上添加同一物品,问最后每个点上哪个物品最多. 解题思路: 1.线段树合并 假如说物品数量少到可以暴力添加,且树点极少,我们怎么做. 首先在一个树节点上标记出哪些物品有多少 ...
- Javascript和jquery事件--键盘事件KeyboardEvent
Js和jq事件—键盘事件KeyboardEvent 键盘事件keydown,keypress和keyup,还需要涉及到一个文本事件textInput. keydown,keypress和keyup事件 ...
- app 自动化测试 Appium+Java可以运行的代码
地址:http://www.cnblogs.com/sunny-sl/p/6520465.html
- [React & Debug] Quick way to debug Stateless component
For example we have the following code: const TodoList = (props) => ( <div className="Tod ...
- [Angular] Using the Argon 2 Hashing Function In Our Sign Up Backend Service
Which hash algorithom to choose for new application: https://www.owasp.org/index.php/Password_Storag ...
- Android 解决RecyclerView删除Item导致位置错乱的问题
RecyclerView的刷新分为内容变化和结构变化,结构变化比如remove和insert等并不会导致viewholder的更新,所以有时候我们使用 notifyItemRemoved(positi ...