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

Entity Framework schedule query

c# entity-framework scheduler

I know that nhibernate has a scheduler that will execute a function at certain intervals. I was wanting this same functionality with EF.

Rewriting urls with mod_rewrite - GET variables

php .htaccess mod-rewrite get

I found out I could make clean urls with mod_rewrite. I managed to make pages like /home.php viewable by visiting /home (without .php).

How to get ActionBar view?

android view android-actionbar android-actionbar-compat showcaseview

I'm using the Showcase library to explain my application feature to

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.