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

Combines values from two streams based on the “lifetime” of each value, represented by an IObservable selected for each value. All combinations of values from both streams that occur during this “lifetime” window are sent to a selector to be combined. The output of this selector is emitted to the output stream.

function join(right : IObservable, leftWindowSelector : Function, 
    rightWindowSelector : Function, joinSelector : Function) : IObservable

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

See also [groupJoin]

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 and right that are both “alive” at the same time are sent to “joinSelector”, the result of which is emitted from the 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──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