title: Monadic IO with ramda and ramda-fantasy
body: <p>Trying to figure out how the IO monad works. </p>
  
  <p>Using the code below I read <code>filenames.txt</code> and use the results to rename files in the directory <code>testfiles</code>. This is obviously unfinished, so instead of actually renaming anything I log to console. :)</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>I call <code>runIO</code> twice, but it feels like it only should be called
  once, in the end?</li>
  <li>I'm want to use <code>renameIO</code> instead of <code>renaneDirect</code> but can't
  find the proper syntax.</li>
  </ol>
  
  <p>Any other suggestions are also appreciated, I'm new to FP!</p>
  
  <pre><code>    var R = require('ramda');
      var IO = require('ramda-fantasy').IO
      var fs = require('fs');
  
      const safeReadDirSync = dir =&gt; IO(() =&gt; fs.readdirSync(dir));
      const safeReadFileSync = file =&gt; IO(() =&gt; fs.readFileSync(file, 'utf-8'));
  
      const renameIO = (file, name) =&gt; IO(() =&gt; console.log('Renaming file ' + file + ' to ' + name + '\n'));
      const renameDirect = (file, name) =&gt; console.log('Renaming file ' + file + ' to ' + name + '\n');
  
      safeReadFileSync("filenames.txt") // read future file names from text file
              .map(R.split('\n')) // split into array
              .map(R.zip(safeReadDirSync('./testfiles/').runIO())) // zip with current file names from dir
              .map(R.map(R.apply(renameDirect))) // rename
              .runIO(); // go!
  </code></pre>