Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As an aside to Enigmativity's well fleshed-out answer, there are 2 things going on here:</p> <ol> <li><p>Observables like Enumerables compose lazily. Just like you wouldn't expect any combinator in an enumerable query to be evaluated until your move through the enumerator, you should expect that consumers will see the all combinators evaluated for that pipeline, as many times as the number of observers subscribing to the pipeline. In short, <code>x &lt;- stream, y &lt;- stream</code> already makes it twice. </p></li> <li><p>The comprehension is rewritten as:</p> <pre><code> stream1.Where(x =&gt; x % 2 == 1) .SelectMany(x =&gt; stream2 .Where(y =&gt; y % 2 == 0 &amp;&amp; y == x + 1) .Select(y =&gt; new { x, y }) ); </code></pre> <p>For every value of x received, you will make a subscription to all the values of the stream which match the predicate - which becomes a lot. Query comprehensions are generally de-sugared as <code>SelectMany</code>/<code>Join</code>/<code>GroupBy</code> - most of Rx you'll practically end up using might be better expressed in terms of other operators - such as <code>Merge</code> or <code>Zip</code> or even <code>Join</code>.</p></li> </ol> <p>There's a question which is extremely similar to the one you've just asked: <strong><a href="https://stackoverflow.com/questions/12319204/is-reactive-extensions-evaluating-too-many-times">Is Reactive Extensions evaluating too many times?</a></strong></p> <p>There's a bit of a discussion on why this is the expected behavior in Rx.</p>
    singulars
    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.
    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