title: Map flatten and flatmap not equivalent
body: <p>I thought that <a href="http://www.brunton-spall.co.uk/post/2011/12/02/map-map-and-flatmap-in-scala/" rel="nofollow noreferrer">Scala construct <code>map(f).flatten</code> was equivalent to <code>flatMap(f)</code></a>. But with this example, it is not the case. I wonder what is the role of the case class in it. If I use integers,  both are equivalent. But in my case, I cannot.</p>
  
  <pre><code>case class CTest(v: Int)
  val s = Set(Map(CTest(0) -&gt; List(0, 3), CTest(1) -&gt; List(0, 2)))
  val possibilities = s flatMap { m =&gt;
    val mapping = m flatMap {
      case (label, destNodes) =&gt; destNodes map {
        case nodes =&gt; (label, nodes) }
    }
    mapping
  }
  possibilities
  </code></pre>
  
  <p>Yields</p>
  
  <pre><code>Set((CTest(0),3), (CTest(1), 2))
  </code></pre>
  
  <p>whereas</p>
  
  <pre><code>case class CTest(v: Int)
  val s = Set(Map(CTest(0) -&gt; List(0, 3), CTest(1) -&gt; List(0, 2)))
  val possibilities = s flatMap { m =&gt;
    val mapping = m map {
      case (label, destNodes) =&gt; destNodes map {
        case nodes =&gt; (label, nodes) }
    }
    mapping.flatten
  }
  possibilities
  </code></pre>
  
  <p>yields</p>
  
  <pre><code>Set((CTest(0),0), (CTest(0),3), (CTest(1),0), (CTest(1),2))
  </code></pre>
  
  <p>Any idea why?</p>