title: Map versus FlatMap on String
body: <p>Listening to the Collections lecture from <a href="https://www.coursera.org/course/progfun" rel="noreferrer">Functional Programming Principles in Scala</a>, I saw this example:</p>
  
  <pre><code>scala&gt; val s = "Hello World"
  
  scala&gt; s.flatMap(c =&gt; ("." + c)) // prepend each element with a period
  res5: String = .H.e.l.l.o. .W.o.r.l.d
  </code></pre>
  
  <p>Then, I was curious why Mr. Odersky didn't use a <code>map</code> here. But, when I tried map, I got a different result than I expected.</p>
  
  <pre><code>scala&gt; s.map(c =&gt; ("." + c))
  res8: scala.collection.immutable.IndexedSeq[String] = Vector(.H, .e, .l, .l, .o, 
                                                            ". ", .W, .o, .r, .l, 
  </code></pre>
  
  <p>I expected that above call to return a String, since I'm <code>map</code>-ing, i.e. applying a function to each item in the "sequence," and then returning a new "sequence."</p>
  
  <p>However, I could perform a <code>map</code> rather than <code>flatmap</code> for a <code>List[String]</code>:</p>
  
  <pre><code>scala&gt; val sList = s.toList
  sList: List[Char] = List(H, e, l, l, o,  , W, o, r, l, d)
  
  scala&gt; sList.map(c =&gt; "." + c)
  res9: List[String] = List(.H, .e, .l, .l, .o, ". ", .W, .o, .r, .l, .d)
  </code></pre>
  
  <p>Why was a <code>IndexedSeq[String]</code> the return type of calling <code>map</code> on the String?</p>