title: Chaining observables and passing result values
body: <p>I want to translate the following code into a reactive flow (using <code>System.Reactive</code> in C#).</p>
  
  <p><code>Method1</code>, <code>Method2</code> and <code>Method3</code> are long running tasks. The result of <code>Method2</code> is necessary in order to call <code>Method3</code>, but <code>Method1</code> and <code>Method2</code> can run in parallel. If <code>result1 == null</code> the whole operation can be terminated early with <code>null</code>.</p>
  
  <p>Usually, <code>Method2</code> returns faster than <code>Method1</code>, so <code>Method3</code> could be started before <code>Method1</code> finishes.</p>
  
  <pre class="lang-cs prettyprint-override"><code>var result1 = Method1();
  if (result1 == null) return null;
  
  var result2 = Method2();
  
  string result3 = null;
  if (result2 != null)
  {
      result3 = Method3(result2);
  }
  
  var combinedResult = CreateResult(result1);
  if (result2 != null)
  {
      combinedResult.Attr2 = result2;
  }
  if (result3 != null)
  {
      combinedResult.Attr3 = result3;
  }
  </code></pre>
  
  <p>I am lost between nested functions and generics. The following code does not compile, because it has issues with generics and return types (especially the nested <code>Select</code> does not return a value but an <code>Observable</code>).</p>
  
  <pre class="lang-cs prettyprint-override"><code>var observable1 = Observable.Start(() =&gt; Method1());
  var observable2 = Observable.Start(() =&gt; Method2());
  Observable.Zip(observable1, observable2, (result1, result2) =&gt;
  {
      if (result2 != null)
      {
          var observable3 = Observable.Start(() =&gt; Method3(result2));
          return observable3.Select(result3 =&gt; 
          {
              return SuperCombiner(result1, result2, result3);
          };
      }
      return SuperCombiner(result1, null, null);
  };
  </code></pre>