MostlyAdequate / mostly-adequate-guide

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

Ch9 Exercise B Solution question #613

Closed efagerberg closed 3 years ago

efagerberg commented 3 years ago

In the following solution:

// We now consider the following items:
//
//   // getFile :: IO String
//   const getFile = IO.of('/home/mostly-adequate/ch09.md');
//
//   // pureLog :: String -> IO ()
//   const pureLog = str => new IO(() => console.log(str));
//
// Use getFile to get the filepath, remove the directory and keep only the basename,
// then purely log it. Hint: you may want to use `split` and `last` to obtain the
// basename from a filepath.

// logFilename :: IO ()
const basename = map(compose(last, split('/')));
const logFilename = compose(
  chain(pureLog),
  basename,
)(getFile);

Why must getFile be put outside of the compose arguments?

efagerberg commented 3 years ago

Nevermind I realize why, because getFile is not a function but an IO with a value already.