title: Building an RX operator to split one observable of key-value-pairs into multiple observables, one per distinct key
body: <p>I'm an RX newbie trying to construct something that seems complex to me.</p>
  
  <p>Here's the problem: I have a hot observable that is producing key-value pairs, let's say &lt;int, foo&gt;. They're coming in no particular order. The output should be an observable for each distinct key in the source observable. So, for each value in the source, the result should be: a new observable if the key has not been seen yet, with the new observable immediately producing the corresponding value. If the key has been seen before, the corresponding value should be produced by the corresponding observable that already exists. So:</p>
  
  <pre><code>&lt;1, foo&gt;-&lt;2, foo&gt;-&lt;2, foo&gt;-&lt;1, foo&gt;-&lt;3, foo&gt;-&lt;4, foo&gt;-&lt;1, foo&gt;-&lt;3, foo&gt;x
  
  Output:
  &lt;1, foo&gt;-------------------&lt;1, foo&gt;-------------------&lt;1, foo&gt;---------x
  ---------&lt;2, foo&gt;-&lt;2,foo&gt;----------------------------------------------x
  ------------------------------------&lt;3, foo&gt;-------------------&lt;3, foo&gt;x
  ---------------------------------------------&lt;4, foo&gt;------------------x
  </code></pre>
  
  <p>I'm attempting this with window, but am stuck on how to "detect" that a key has already been seen and then "route" the value to the existing observable.</p>
  
  <p>Thanks!</p>