Mark Elston (132) [Avatar] Offline
#1
I am having trouble understanding the role of the lambda passed in to the Publish call in page 191. In particular how does this 'selector' function eliminate the issue shown in the previous example? And what actually is this function 'selecting'?
Tamir Dresher (35) [Avatar] Offline
#2
Hi Mark,
The Zip example (without publish), does two isolated subscription to the the numbers observable. in this case, because the numbers observable is cold, it will generate the entire sequence twice, meaning that the increment of i will happen 10 time, 5 times to generate the sequence for the first subscription, and 5 times for the second subscription. therefore, the "zipping" in each iteration will occur for pairs of (i+1,i+2) where i is the initial value in the iteration.

The Publish operator turns the cold observable to a hot one, so all subscription to the hot observable will share the same sequence. The selector function that is passed to the Publish operator, receives the hot observable and can use it and subscribe to it multiple times (and all of them will share the sequence), the returned observable from the selector function is the one that will be returned from the Publish operator.
So this time, in Zip operator, is "zipping" the same element that is coming from the two subscriptions, therefore the pairs are of the same element (i,i).

I hope i helped clearing it now

Mark Elston (132) [Avatar] Offline
#3
So you are saying that ys in the second example is the published version of numbers, and that the two uses of it in the lambda with Zip are going to be fed the same values in each 'iteration'.
Tamir Dresher (35) [Avatar] Offline
#4
Exactly