diff --git a/ch12.md b/ch12.md index 2da8c85c..903538a8 100644 --- a/ch12.md +++ b/ch12.md @@ -12,7 +12,7 @@ Let's get weird: // readFile :: FileName -> Task Error String // firstWords :: String -> String -const firstWords = compose(intercalate(' '), take(3), split(' ')); +const firstWords = compose(intercalate(' '), take(3), split(' '), toString); // tldr :: FileName -> Task Error String const tldr = compose(map(firstWords), readFile); @@ -149,7 +149,7 @@ Time to revisit and clean our initial examples. // readFile :: FileName -> Task Error String // firstWords :: String -> String -const firstWords = compose(intercalate(' '), take(3), split(' ')); +const firstWords = compose(intercalate(' '), take(3), split(' '), toString); // tldr :: FileName -> Task Error String const tldr = compose(map(firstWords), readFile); diff --git a/support/index.js b/support/index.js index 31d5ab23..0c285305 100644 --- a/support/index.js +++ b/support/index.js @@ -600,7 +600,11 @@ const toUpperCase = s => s.toUpperCase(); // traverse :: (Applicative f, Traversable t) => (a -> f a) -> (a -> f b) -> t a -> f (t b) -const traverse = curry((of, fn, f) => f.traverse(of, fn)); +const traverse = curry((of, fn, f) => + Array.isArray(f) + ? f.reduce((innerF, a) => fn(a).map(append).ap(innerF), of([])) + : f.traverse(of, fn) +); // unsafePerformIO :: IO a -> a