title: How do you flatten a Sequence of Sequence in DBIOaction SLICK?
body: <p>Hey guys i am new in slick, how can I flatten this sequence of sequence? so that can return the commented code</p>
  
  <pre><code>    def insertIfNotExists(mapCountryStates: Map[String, Iterable[StateUtil]]): Future[Seq[Seq[StateTable]]] /*: Future[Seq[StateTable]]*/ = {
      val interaction = DBIO.sequence(mapCountryStates.toSeq.map { case (alpha2Country, statesUtil) =&gt;
        val codes = statesUtil.map(_.alpha3Code)
        for {
          countryId &lt;- Countries.filter(_.alpha2Code === alpha2Country).map(_.id).result.head
          existing &lt;- States.filter(s =&gt; (s.alpha3Code inSet codes) &amp;&amp; s.countryId === countryId).result
          stateTables = statesUtil.map(x =&gt; StateTable(0L, x.name, x.alpha3Code, countryId))
          statesInserted &lt;- StatesInsertQuery ++= stateTables.filter(s =&gt; !existing.exists(x =&gt; x.alpha3Code == s.alpha3Code &amp;&amp; x.countryId == s.countryId))
        } yield existing ++ statesInserted
      })
  
      db.run(interaction.transactionally)
    }
  </code></pre>
  
  <p>if I write it here:</p>
  
  <p>val interaction = DBIO.sequence(...).<strong>flatten</strong></p>
  
  <p>or here:</p>
  
  <p>db.run(interaction.<strong>flatten</strong>.transactionally)</p>
  
  <p>[error] Cannot prove that Seq[Seq[StateRepository.this.StateTableMapping#TableElementType]] &lt;:&lt; slick.dbio.DBIOAction[R2,S2,E2].</p>
  
  <p>but when the application runs, because the IDE does not detect it as an error:
  <a href="https://i.stack.imgur.com/yCWmz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yCWmz.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/kdWnU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kdWnU.png" alt="enter image description here"></a></p>
  
  <p>I update my definition with <strong>DBIO.fold:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/qwvHB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qwvHB.png" alt="enter image description here"></a></p>