We use the traversable instance on List to reimplement Promise.all() type functionality.

For example we want to conver:

[Task] => Task([])

Conver array of Task, into Task of array value.

To do that we can use traverse.

Noraml Javascript array doesn't have traverse method, so we need to bring immutable-ext.

const fs = require('fs')
const Task = require('data.task')
const futurize = require('futurize').futurize(Task)
const { List } = require('immutable-ext') const readFile = futurize(fs.readFile) const files = List(['box.js', 'config.json']) files.traverse(Task.of, fn => readFile(fn, 'utf-8'))
.fork(console.error, console.log)

Here 'futurize' give us a easy way to wrap a function into a Task. We can do it manually as well:

/*
const readFile = (filename, encode) => new Task((rej, res) => {
return fs.readFile(filename, encode, (err, content) => {
if (err) rej(err);
res(content);
});
});*/
const readFile = futurize(fs.readFile);

[Compose] 19. Leapfrogging types with Traversable的更多相关文章

  1. [JS Compose] 5. Create types with Semigroups

    An introduction to concatting items via the formal Semi-group interface. Semi-groups are simply a ty ...

  2. C#复习④

    C#复习④ 2016年6月16日 12:37 Main Classes and Structs 类和结构体 1.Contents of Classes 字段,常量,方法,构造函数,析构函数: 特性,事 ...

  3. Java反射机制能够获取的信息,与应用

    一.什么是Java反射机制? [1]反射机制是在运行状态中,对于任何一个类,都能够知道这个类的所有属性和方法: [2]对于任意一个对象,都能够调用它的任意一个属性和方法: 像这种动态获取类的信息以及动 ...

  4. Effective Java 第三版——29. 优先考虑泛型

    Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...

  5. Python3 与 C# 扩展之~基础拓展

      上次知识回顾:https://www.cnblogs.com/dotnetcrazy/p/9278573.html 代码裤子:https://github.com/lotapp/BaseCode ...

  6. 【大数据】SparkSql学习笔记

    第1章 Spark SQL概述 1.1 什么是Spark SQL Spark SQL是Spark用来处理结构化数据的一个模块,它提供了2个编程抽象:DataFrame和 DataSet,并且作为分布式 ...

  7. 6、Qt Meta Object system 学习

    原文地址:http://blog.csdn.net/ilvu999/article/details/8049908 使用 meta object system 继承自 QOject 类定义中添加 Q_ ...

  8. FastDFS 环境搭建

    原文地址:FastDFS 环境搭建 博客地址:http://www.extlight.com 一.前言 最近闲下来,整理了一下笔记,今天就分享一下 FastDFS 环境搭建吧. 二.介绍 2.1 Fa ...

  9. Spring MVC SessionAttributes ModelAttribute注解

    说明 本文主要针对 @SessionAttributes注解 和 @ModelAttribute注解的基础用法进行解析.至于为什么会将这两个注解放在一起,是因为它们之间还是有点影响的. @Sessio ...

随机推荐

  1. Java面向对象封装和继承

    面向对象 什么是面向过程.面向对象? 面向过程与面向对象都是我们编程中,编写程序的一种思维方式. 面向过程的程序设计方式,是遇到一件事时,思考“我该怎么做”,然后一步步实现的过程.例如:公司打扫卫生( ...

  2. 11.6八校联考T1,T2题解

    因为版权问题,不丢题面,不放代码了(出题人姓名也隐藏) T1 这,是一道,DP题,但是我最开始看的时候,我思路挂了,以为是一道简单题,然后就写错了 后来,我正确理解题意后写了个dfs,幸亏没有记忆化, ...

  3. luoguP4284 [SHOI2014]概率充电器 概率期望树形DP

    这是一道告诉我概率没有想象中那么难的题..... 首先,用期望的线性性质,那么答案为所有点有电的概率和 发现一个点的有电的概率来源形成了一个"或"关系,在概率中,这并不好计算... ...

  4. [BZOJ4872][六省联考2017]分手是祝愿(期望DP)

    4872: [Shoi2017]分手是祝愿 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 516  Solved: 342[Submit][Statu ...

  5. 压测工具Siege

    一.下载 http://www.joedog.org/ http://www.joedog.org/pub/siege/siege-2.70.tar.gz 二.测试 siege -c200 -r10 ...

  6. hibernate之条件查询

    一.条件查询简介 条件查询是更据面向对象特色的数据查询方式,主要通过如下3个类完成 1.Criteria:代表一次查询 2.Criterion:代表一个查询条件 3.Restrictions:产生查询 ...

  7. 【原创】Eclipse中Android项目引用

    1.选择名为SMSSDK的项目,右键--->Properties--->Android--->将Is Library勾上--->OK. 2.选中另一个名为FragmentDem ...

  8. HDU 5642 King's Order 动态规划

    King's Order 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 Description After the king's speec ...

  9. hdu 4114 Disney's FastPass 状压dp

    Disney's FastPass Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  10. gdb参考手册

    http://www.sourceware.org/gdb/current/onlinedocs/gdb.html