MostlyAdequate / mostly-adequate-guide

Mostly adequate guide to FP (in javascript)
Other
23.29k stars 1.86k forks source link

fixing Waltz of the Types first example #606

Open dotnetCarpenter opened 3 years ago

dotnetCarpenter commented 3 years ago

By using the improved traverse function from https://github.com/MostlyAdequate/mostly-adequate-guide/issues/581#issuecomment-668274810 and adding toString since the nodejs fs.readFile returns a Buffer and not a String.

// readFile :: FileName -> Task Error String

// firstWords :: String -> String
const firstWords = compose(intercalate(' '), take(3), split(' '), toString);

// tldr :: FileName -> Task Error String
const tldr = compose(map(firstWords), readFile);

traverse(Task.of, tldr, ['file1', 'file2']);
// Task(['hail the monarchy', 'smash the patriarchy']);

Before the traverse function threw a TypeError: f.traverse is not a function, on traverse(Task.of, tldr, ['file1', 'file2']);.

Thanks to @antonklimov.

dotnetCarpenter commented 3 years ago

Blocks #607