How can I Switch() two streams, and emit an intermediate event between them?

I have a Stream of Streams. When one stream ends, and the next begins, I need to emit an intermediate event that bridges them. This needs to occur after the last event of the previous stream, and needs to mutate the state of the last event. Basically, the output stream needs to look like this:

Stream 1 - event 1
Stream 1 - event 2
Stream 1 - event 3  (Stream 1 completes)
* My bridging event (Mutation of event 3)
Stream 2 - event 1 etc

Answers


Simply transform each of the inner sequences with a single concatenated mutation of the last element.

IObservable<IObservable<T>> source = ...;
Func<T, T> mutation = ...;
IObservable<T> query = source
    .Select(innerSource => innerSource
        .Publish(o => o.Concat(o.LastAsync().Select(mutation))))
    .Concat();

Note this assumes that each inner stream always has at least one item.


Need Your Help

Retrieving XML type records from Oracle Database in QTP

xml database testing qtp

I want to fetch records from an Oracle database that contain XML files in them. When I try to fetch other columns from the same table, it successfully returns, like a number or a text, but the column

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.