title: How can I flatten this Future[T] structure?
body: <p>Given the following example:</p>
  
  <pre><code>  val handler : Connection = new DatabaseConnectionHandler()
    val result : Future[Future[Future[Option[ResultSet]]]] = handler.connect
      .map( (parameters) =&gt; handler )
      .map( connection =&gt; connection.sendQuery("BEGIN TRANSACTION SERIALIZABLE") )
      .map( future =&gt; future.map( query =&gt; query.rows ) )
      .map( future =&gt; handler.sendQuery("COMMIT").map( query =&gt; future ) )
  </code></pre>
  
  <p>Is it possible to flatten it to receive a <code>Future[Option[ResultSet]]</code> at the end instead of this future inside a future inside a future structure in Scala?</p>
  
  <p>I am currently using Scala's 2.10 Future's and Promise's, but I can't find a way to to this. I know I can use nested callbacks but I would rather avoid that since the code is going to look horrible.</p>
  
  <p>The <code>Connection</code> trait is defined <a href="https://github.com/mauricio/postgresql-netty/blob/master/src/main/scala/com/github/mauricio/postgresql/Connection.scala" rel="noreferrer">here</a>.</p>