Synchronous logging of asynchronous retrieved folder info
I decided to go with the solution below.
By using Tasks I don't need to put all the logic right there, I can just pass the Task anywhere and map/chain over it to add extra functionality. I can even just fork it after I have all the data and get the List inside which I can also map and more.
Also with the function &quot;getsubfolders&quot; from the questions I can use to get the array of the paths and just wrap it in a List as I am doing in readDir.
So what I mean is that, although the structure is different, this way is way more flexible and readable (I can still derive all the above objects from the result).
I am noew trying to convert the getsubfolders to async and functional as well, for the sake of learning.
/* eslint-disable import/extensions */
/*
taken from 
https://mostly-adequate.gitbooks.io/mostly-adequate-guide/content/ch08.html#asynchronous-tasks
 */
import fs from 'fs'
import {Task, traverse,concat,compose,chain,map, prop, List, } from './shared/functional.js';

// readDir :: String -&gt; Task Error (List String)
const readDir = path =&gt; new Task((reject, result) =&gt; {
  fs.readdir(path, (err, data) =&gt; (err ? reject(err) : result(new List(data))));
});

// readDir :: String -&gt; Task Error (Stat)
const readStat = filename =&gt; new Task((reject, result) =&gt; {
  fs.stat(filename, (err, data) =&gt; (err ? reject(err) : result(data)));
});

const dirList = dir =&gt; 
chain(
  traverse(Task.of, compose(readStat, concat(dir))),
  readDir(dir),
);

dirList('./shared/').fork(console.error, map(compose(console.log, prop('mtimeMs'))));