Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a fairly neat observable query that seemed to work properly for me:</p> <pre><code>var below50longerthan10seconds = subject .Select(x =&gt; x &lt; 50) .DistinctUntilChanged() .Select(x =&gt; Observable.Delay( Observable.Return(x), TimeSpan.FromSeconds(10.0))) .Switch() .Where(x =&gt; x) .Select(x =&gt; Unit.Default); </code></pre> <p>Here's the breakdown.</p> <p>Change the values from 0 to 100 to <code>true</code> when less than 50 and <code>false</code> otherwise:</p> <pre><code> .Select(x =&gt; x &lt; 50) </code></pre> <p>Only keep the actual changes between <code>true</code> &amp; <code>false</code>:</p> <pre><code> .DistinctUntilChanged() </code></pre> <p>Project the value into a new observable that is delayed for 10 seconds:</p> <pre><code> .Select(x =&gt; Observable.Delay( Observable.Return(x), TimeSpan.FromSeconds(10.0))) </code></pre> <p>Now perform a <code>.Switch()</code> - if a new <code>x</code> comes before the delayed observable then it is ignored because a new delayed observable is coming:</p> <pre><code> .Switch() </code></pre> <p>Select only the <code>true</code> values meaning when the original stream was below 50:</p> <pre><code> .Where(x =&gt; x) </code></pre> <p>Select <code>Unit.Default</code> simply because it is weird to have a stream of <code>true</code> values without any <code>false</code> values:</p> <pre><code> .Select(x =&gt; Unit.Default); </code></pre> <p>So now you have an <code>IObservable&lt;Unit&gt;</code> that releases a new value when the original stream produces a value less then 50 and does not produce a value greater than or equal to 50 within 10 seconds.</p> <p>Is that what you wanted?</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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