Question: I've done some research concerning reactive linq, also known as Rx.NET. I've seen that the SelectMany method's behavior as the following end result : flattening the content in the observable so it goes from many streams to a single one. My question would be, is there a method that acts in the exactly opposite direction? Meaning that after placing multiple streams of events in one observable ([multiplexing](https://en.wikipedia.org/wiki/Multiplexing)), how would one achieve that ? I know that [GroupBy](http://reactivex.io/documentation/operators/groupby.html) has a pretty similar behavior to what I'm requesting except one thing is missing : I would like an observable for a key that may not have been emitted yet.

I was thinking of implementing the behavior by myself but if by any chance, I have missed the existence of such a method, please, show me that I'm in the wrong and it actually exists !

Answer: 
You are right that `GroupBy` is what you want. It's easy to set it up to subscribe to any key ahead of time. Just do this:

```
IObservable<int> oddNumbers =
    Observable
        .Range(0, 10)
        .GroupBy(x => x % 2)
        .Where(gx => gx.Key == 1)
        .Merge();

```

If I subscribe to that I get:

```

1 
3 
5 
7 
9 

```

However, this is a bit of a waste of time as this is directly the equivalent of:

```
IObservable<int> oddNumbers =
    Observable
        .Range(0, 10)
        .Where(x => x % 2 == 1);

```

The only way that I can see that it might be useful is if you did this:

```
IConnectableObservable<IGroupedObservable<int, int>> groupedNumbers =
    Observable
        .Range(0, 10)
        .GroupBy(x => x % 2)
        .Publish();

Func<IConnectableObservable<IGroupedObservable<int, int>>, int, IObservable<int>> anyProject =
    (source, key) =>
        source
            .Where(gx => gx.Key == key)
            .Merge();

IObservable<int> oddNumbers = anyProject(groupedNumbers, 1);

oddNumbers.Subscribe(x => Console.WriteLine(x));

groupedNumbers.Connect();

```

That still gives me the odd numbers, but I can now create the even numbers observable without starting a new grouping.
`GroupBy` is what you are looking for, but as you point out, it does fall short on creating "known" groups up front. However I imagine you could be creative and seed your sequence with values for each of these known groups as such:

if the source was like this 

```
Observable.Interval(TimeSpan.FromMilliseconds(100))
    .GroupBy(i => i % 4)

```

You could modify that to be something like 

```
var seed = new[] { 0L, 1L, 2L, 3L }.ToObservable();
Observable.Concat(seed, Observable.Interval(TimeSpan.FromMilliseconds(100)))
    .GroupBy(i => i % 4)
    .Select(grp=>grp.Skip(1))   //Ignore the first/seed value.

```