title: map vs flatMap in reactor
body: <p>I've found a lot of answers regarding <a href="https://stackoverflow.com/questions/22847105/when-do-you-use-map-vs-flatmap-in-rxjava">RxJava</a>, but I want to understand how it works in Reactor.</p>
  
  <p>My current understanding is very vague, i tend to think of map as being synchronous and flatMap to be asynchronous but I can't really get my had around it.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>files.flatMap { it -&gt;
      Mono.just(Paths.get(UPLOAD_ROOT, it.filename()).toFile())
          .map {destFile -&gt;
              destFile.createNewFile()
              destFile    
          }               
          .flatMap(it::transferTo)
  }.then()  
  </code></pre>
  
  <p>I have files (a <code>Flux&lt;FilePart&gt;</code>) and i want to copy it to some <code>UPLOAD_ROOT</code> on the server.</p>
  
  <p>This example is taken from a book.</p>
  
  <p>I can change all the <code>.map</code> to <code>.flatMap</code> and vice versa and everything still works. I wonder what the difference is.</p>