I personally would avoid Do statements.
You could create a projection.
In this projection, I assume that you want to take your action to delete the current internal sequence (perhaps clear current records from the table?)
MagicSource(StringsProvider) .Select(inner=>inner.Finally(CleanUp)) .Switch() .Subscribe(r => {});
If you want to do the same, but aim at subscribing (rather than deleting) the internal sequence, then you will need a little more work. I would create a symmetric operator, finally Initially(Action)
public static class ObservableEx { public static IObservable<T> Initially<T>(this IObservable<T> source, Action onSubscribe) { return Observable.Create<T>(o=>{ try { onSubscribe(); return source.Subscribe(o); } catch (Exception ex) { o.OnError(ex); return Disposable.Empty; } }); } }
And then you can use it like this:
MagicSource(StringsProvider) .Select(inner=>inner.Initially(Prepare)) .Switch() .Subscribe(r => {});
source share