Skip to content
richardszalay edited this page May 20, 2011 · 5 revisions

Combines values from two streams based on the “lifetime” of each value, represented by an IObservable selected for each value. Each left value is sent a selector along with an IObservable of potential future right value matches. The output of this selector is emitted to the output stream.

  rightWindowSelector : Function, joinSelector : Function) : IObservable

leftWindowSelector is function(leftValue : TLeft) : IObservable.<*>
rightWindowSelector is function(rightValue : TRight) : IObservable.<*>
joinSelector is function(leftValue : TLeft, rightValue : IObservable.<TRight>) : IObservable.<TResult>

Remarks

Similar to a cartesion join, but instead of joining on a value it joins on “time” with the active lifetime for the two sequences are selected by leftWindowSelector and rightWindowSelector. Values from the left are sent to the joinSelector along with an IObservable of potential right values; any right values that are still active when a left window begins are immediately emitted to the “right values” IObservable sequence.

The sequence completes when no further matches can logically occur.

The sequence errors if either the left or right sequences error or any of the lifetime windows error.

Marble Diagrams

vs, ls = left (source)
rs     = right
lws    = leftWindowSelector
lws    = rightWindowSelector
f()    = joinSelector(left, right)
"i"    = lifetime of i
ys     = output

      0           4
ls ───o───────────o────
      │           │
      │  1  2  3  │
rs ──────o──o──o─/│
      │  │  │  │  │
"0"   └──┼──┼/ │  │
"4"   │  │  │  │  └────
"1"   │  └──┼/ │  │
"2"   │  │  └──┼──┼───/
"3"   │  │  │  └──┼┬/ │
      │  │  │  │  ││  │
      │  f  f  f  ff  │
      │  │  │  │  ││  │
ys ───o──┼──┼──o──┼o──/
      └──o──o/    │└┐ │
                  └oo─/ 

In the above example 0 and 4 are emitted (at different times) from the left sequence and 1, 2 and 3 are emitted from the right sequence. Values 1 and 2 occur within 0’s lifetime so are emitted via resultSelector. Value 4 is emitted during 2 and 3’s lifetime, so two more values are emitted (4,2 and 4,3). The sequence completes after 2’s lifetime ends because the right sequence has already completed and there are no more active right values so no more combinations can occur.

Return Value

IObservable.<TResult>

Examples

```as3
```

Clone this wiki locally