Reactive Programming, Posting # 9
Reactive Extensions (Rx) has a number of operators that we’ve looked at already, including Select, Throttle, Subscribe and so forth. While SelectMany is not the most important Rx operator, it is surely the most powerful.
SelectMany’s principal job is to allow you to select against an IObservable<T>, run a func<u> and get back an IObservable<u>
IObservable<U> SelectMany(IObservable<T>, func<U>)
Read that in your head “SelectMany takes an IObservable of T and a func (funk) of U and returns an IObservable of U.” |
Today we’ll take a look at the case of having a function that returns an IObservable and you wish to then pass the results to a function that returns an IObservable. That is, the case where you wan to chain calls. If you were to use Select, you would end up with an IObservable<IObservable<T>> which is not what you want. SelectMany flattens that for you.