title: How to map RxSwift Observable and Result
body: <p>I have a quick question:</p>
  
  <ul>
  <li>I have a network request that returns <code>Observable&lt;Result&lt;String, RequestError&gt;&gt;</code>, let’s call it <code>requestToken</code></li>
  <li>if this request succeeds, I want to use the <code>String</code> (token) to do another request that returns <code>Observable&lt;Result&lt;NSDictionary, RequestError&gt;&gt;</code>, let’s call it <code>requestData</code></li>
  <li>when that second request comes back, I wanna merge the token into its dictionary</li>
  <li>in the end I wanna map from <code>Observable&lt;Result&lt;String, RequestError&gt;&gt;</code> to <code>Observable&lt;Result&lt;NSDictionary, RequestError&gt;&gt;</code></li>
  </ul>
  
  <p>How can I achieve that without multiple nested levels in my code?</p>
  
  <p>This is what I have today:</p>
  
  <pre><code>requestToken()
      .flatMap({ result -&gt; Observable&lt;Result&lt;NSDictionary, RequestError&gt;&gt; in
          switch result {
          case .success(let token):
              return requestData(token: token).map({ $0.map({ $0 + ["token": token] }) })
          case .failure(let error):
              return Observable.of(.failure(error))
          }
      })
  </code></pre>