码迷,mamicode.com
首页 > 其他好文 > 详细

[Compose] 19. Leapfrogging types with Traversable

时间:2016-12-21 21:34:06      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:pos   file   frog   ext   function   list   ror   fork   read   

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.

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)

 

[Compose] 19. Leapfrogging types with Traversable

标签:pos   file   frog   ext   function   list   ror   fork   read   

原文地址:http://www.cnblogs.com/Answer1215/p/6208930.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!