Join
combine items emitted by two Observables whenever an item from one Observable is emitted during a time window defined according to an item emitted by the other Observable

The Join
operator combines the items emitted by two Observables, and selects which items to combine based on duration-windows that you define on a per-item basis. You implement these windows as Observables whose lifespans begin with each item emitted by either Observable. When such a window-defining Observable either emits an item or completes, the window for the item it is associated with closes. So long as an item’s window is open, it will combine with any item emitted by the other Observable. You define the function by which the items combine.

Most ReactiveX implementations that have a Join
operator also have a GroupJoin
operator that is similar, except that the function you define to combine items emitted by the two Observables pairs individual items emitted by the source Observable not with an item from the second Observable, but with an Observable that emits items from the second Observable that fall in the same window.
See Also
- CombineLatest
- Zip
- Introduction to Rx: Join
- Introduction to Rx: GroupJoin
- 101 Rx Samples: GroupJoin — Joins two streams by matching by one of their attributes
Language-Specific Information
RxGroovy join groupJoin

The join
operator takes four parameters:
- the second Observable to combine with the source Observable
- a function that accepts an item from the source Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the second Observable
- a function that accepts an item from the second Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the first Observable
- a function that accepts an item from the first Observable and an item from the second Observable and returns an item to be emitted by the Observable returned from
join
join
does not by default operate on any particular Scheduler.
- Javadoc:
Join(Observable,Func1,Func1,Func2)

The groupJoin
operator takes four parameters:
- the second Observable to combine with the source Observable
- a function that accepts an item from the source Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the second Observable
- a function that accepts an item from the second Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the first Observable
- a function that accepts an item from the first Observable and an Observable that emits items from the second Observable and returns an item to be emitted by the Observable returned from
groupJoin
groupJoin
does not by default operate on any particular Scheduler.

Note that there is also a join
operator in the optional StringObservable
class. It converts an Observable that emits a sequence of strings into an Observable that emits a single string that concatenates them all, separating them by a specified string delimiter.
RxJava 1․x join groupJoin

The join
operator takes four parameters:
- the second Observable to combine with the source Observable
- a function that accepts an item from the source Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the second Observable
- a function that accepts an item from the second Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the first Observable
- a function that accepts an item from the first Observable and an item from the second Observable and returns an item to be emitted by the Observable returned from
join
join
does not by default operate on any particular Scheduler.
- Javadoc:
Join(Observable,Func1,Func1,Func2)

The groupJoin
operator takes four parameters:
- the second Observable to combine with the source Observable
- a function that accepts an item from the source Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the second Observable
- a function that accepts an item from the second Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the first Observable
- a function that accepts an item from the first Observable and an Observable that emits items from the second Observable and returns an item to be emitted by the Observable returned from
groupJoin
groupJoin
does not by default operate on any particular Scheduler.

Note that there is also a join
operator in the optional StringObservable
class. It converts an Observable that emits a sequence of strings into an Observable that emits a single string that concatenates them all, separating them by a specified string delimiter.
RxJS join groupJoin

The join
operator takes four parameters:
- the second Observable to combine with the source Observable
- a function that accepts an item from the source Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the second Observable
- a function that accepts an item from the second Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the first Observable
- a function that accepts an item from the first Observable and an item from the second Observable and returns an item to be emitted by the Observable returned from
join
Sample Code
var xs = Rx.Observable.interval(100) .map(function (x) { return 'first' + x; }); var ys = Rx.Observable.interval(100) .map(function (x) { return 'second' + x; }); var source = xs .join( ys, function () { return Rx.Observable.timer(0); }, function () { return Rx.Observable.timer(0); }, function (x, y) { return x + y; } ) .take(5); var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); });
Next: first0second0 Next: first1second1 Next: first2second2 Next: first3second3 Next: first4second4 Completed

The groupJoin
operator takes four parameters:
- the second Observable to combine with the source Observable
- a function that accepts an item from the source Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the second Observable
- a function that accepts an item from the second Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the first Observable
- a function that accepts an item from the first Observable and an Observable that emits items from the second Observable and returns an item to be emitted by the Observable returned from
groupJoin
Sample Code
ar xs = Rx.Observable.interval(100) .map(function (x) { return 'first' + x; }); var ys = Rx.Observable.interval(100) .map(function (x) { return 'second' + x; }); var source = xs.groupJoin( ys, function () { return Rx.Observable.timer(0); }, function () { return Rx.Observable.timer(0); }, function (x, yy) { return yy.select(function (y) { return x + y; }) }).mergeAll().take(5); var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); });
Next: first0second0 Next: first1second1 Next: first2second2 Next: first3second3 Next: first4second4 Completed
join
and groupJoin
are found in each of the following distributions:
rx.all.js
rx.all.compat.js
rx.coincidence.js
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/join.html