traverse
traverse(always, compose(always, inc), [2, 4, 5])() // => [3, 5, 6]
//////////////////////////////////////////////////////////////////////////////
const getTimeFromStart = startTime => Date.now() - startTime;
const makeFuture = startTime => ms => Future((reject, resolve) => {
console.log('start: ' + ms, 'timeFromStart: ' + getTimeFromStart(startTime));
return setTimeout(() => {
console.log('finish: ' + ms, 'timeFromStart: ' + getTimeFromStart(startTime));
resolve(ms);
}, ms)
});
const futuRes = R.traverse(Future.of, makeFuture(Date.now()), [1000, 5000, 3]);
futuRes.fork(err => console.error(err), data => console.log(data)); //=>
// start: 1000
// timeFromStart: 0
// start: 5000
// timeFromStart: 0
// start: 3
// timeFromStart: 0
// finish: 3
// timeFromStart: 7
// finish: 1000
// timeFromStart: 1006
// finish: 5000
// timeFromStart: 5005
// [1000,5000,3]
// So, method starts all the futures simultaneously. It returns results according to a preassigned order.