Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Suppose we have two methods</p> <ol> <li><strong>Before</strong>, Merges two observable sequences into one observable sequence by using a selector function whenever the first observable produces an element rigth before the second one.</li> <li><strong>Without</strong>, Merges an observable sequence into other observable sequence every time two items came togheter from the first observable without any item from the second one.</li> </ol> <p>With this methods the problem is almost solved.</p> <pre><code>IObservable&lt;TP&gt; P = // observer P IObservable&lt;TQ&gt; Q = // observer Q var PP = P.Without((prev, next) =&gt; 0, Q); var PQ = P.Before(Q, (p,q) =&gt; f(p,q)); // apply the function var ResultSecuence = PP.Merge(PQ); </code></pre> <p>And here are the two methods</p> <pre><code>public static class Observer { /// &lt;summary&gt; /// Merges two observable sequences into one observable sequence by using the selector function /// whenever the first observable produces an element rigth before the second one. /// &lt;/summary&gt; /// &lt;param name="first"&gt; First observable source.&lt;/param&gt; /// &lt;param name="second"&gt;Second observable source.&lt;/param&gt; /// &lt;param name="resultSelector"&gt;Function to invoke whenever the first observable produces an element rigth before the second one.&lt;/param&gt; /// &lt;returns&gt; /// An observable sequence containing the result of combining elements of both sources /// using the specified result selector function. /// &lt;/returns&gt; public static IObservable&lt;TResult&gt; Before&lt;TLeft, TRight, TResult&gt;(this IObservable&lt;TLeft&gt; first, IObservable&lt;TRight&gt; second, Func&lt;TLeft, TRight, TResult&gt; resultSelector) { var result = new Subject&lt;TResult&gt;(); bool firstCame = false; TLeft lastLeft = default(TLeft); first.Subscribe(item =&gt; { firstCame = true; lastLeft = item; }); second.Subscribe(item =&gt; { if (firstCame) result.OnNext(resultSelector(lastLeft, item)); firstCame = false; }); return result; } /// &lt;summary&gt; /// Merges an observable sequence into one observable sequence by using the selector function /// every time two items came from &lt;paramref name="first"/&gt; without any item of any observable /// in &lt;paramref name="second"/&gt; /// &lt;/summary&gt; /// &lt;param name="first"&gt; Observable source to merge.&lt;/param&gt; /// &lt;param name="second"&gt; Observable list to ignore.&lt;/param&gt; /// &lt;param name="resultSelector"&gt;Function to invoke whenever the first observable produces two elements without any of the observables in the secuence produces any element&lt;/param&gt; /// &lt;returns&gt; /// An observable sequence containing the result of combining elements /// using the specified result selector function. /// &lt;/returns&gt; public static IObservable&lt;TResult&gt; Without&lt;TLeft, TResult&gt;(this IObservable&lt;TLeft&gt; first, Func&lt;TLeft, TLeft, TResult&gt; resultSelector,params IObservable&lt;object&gt;[] second) { var result = new Subject&lt;TResult&gt;(); bool firstCame = false; TLeft lastLeft = default(TLeft); first.Subscribe(item =&gt; { if (firstCame) result.OnNext(resultSelector(lastLeft, item)); firstCame = true; lastLeft = item; }); foreach (var observable in second) observable.Subscribe(item =&gt; firstCame = false); return result; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload