0
# Observable Combination
1
2
Operators for combining multiple observable sequences including merge, zip, combineLatest, and concat operations.
3
4
## Capabilities
5
6
### Merge (Static)
7
8
Merges multiple observable sequences into one sequence.
9
10
```javascript { .api }
11
/**
12
* Merges multiple observable sequences into one sequence
13
* @param {...Observable} sources - Observable sequences to merge
14
* @returns {Observable} Merged observable sequence
15
*/
16
Rx.Observable.merge = function(...sources);
17
18
/**
19
* Merges multiple observables with delayed error propagation
20
* @param {...Observable} sources - Observable sequences to merge
21
* @returns {Observable} Merged observable sequence with delayed errors
22
*/
23
Rx.Observable.mergeDelayError = function(...sources);
24
```
25
26
### Merge (Instance)
27
28
Merges with another observable sequence.
29
30
```javascript { .api }
31
/**
32
* Merges with another observable sequence
33
* @param {Observable} other - Observable sequence to merge with
34
* @returns {Observable} Merged observable sequence
35
*/
36
observable.merge = function(other);
37
```
38
39
### Concat (Static)
40
41
Concatenates multiple observable sequences.
42
43
```javascript { .api }
44
/**
45
* Concatenates multiple observable sequences sequentially
46
* @param {...Observable} sources - Observable sequences to concatenate
47
* @returns {Observable} Concatenated observable sequence
48
*/
49
Rx.Observable.concat = function(...sources);
50
```
51
52
### Zip (Static)
53
54
Combines multiple observables using a result selector function.
55
56
```javascript { .api }
57
/**
58
* Combines multiple observables into one by merging their values in pairs
59
* @param {...Observable} sources - Observable sequences to zip
60
* @param {function} [resultSelector] - Function to combine corresponding values
61
* @returns {Observable} Zipped observable sequence
62
*/
63
Rx.Observable.zip = function(...sources, resultSelector);
64
```
65
66
**Usage Example:**
67
68
```javascript
69
var obs1 = Rx.Observable.fromArray([1, 2, 3]);
70
var obs2 = Rx.Observable.fromArray(['a', 'b', 'c']);
71
var zipped = Rx.Observable.zip(obs1, obs2, function(x, y) {
72
return x + y;
73
});
74
// Emits: '1a', '2b', '3c'
75
```
76
77
### Combine Latest (Static)
78
79
Combines the latest values from multiple observables.
80
81
```javascript { .api }
82
/**
83
* Combines the latest values from multiple observables
84
* @param {...Observable} sources - Observable sequences to combine
85
* @param {function} [resultSelector] - Function to combine latest values
86
* @returns {Observable} Combined observable sequence
87
*/
88
Rx.Observable.combineLatest = function(...sources, resultSelector);
89
```
90
91
**Usage Example:**
92
93
```javascript
94
var obs1 = Rx.Observable.interval(1000);
95
var obs2 = Rx.Observable.interval(1500);
96
var combined = Rx.Observable.combineLatest(obs1, obs2, function(x, y) {
97
return {x: x, y: y};
98
});
99
// Emits latest combination whenever either observable emits
100
```
101
102
### With Latest From
103
104
Combines source with latest values from other observables.
105
106
```javascript { .api }
107
/**
108
* Combines source with latest values from other observables
109
* @param {...Observable} sources - Observable sequences to get latest values from
110
* @param {function} resultSelector - Function to combine values
111
* @returns {Observable} Combined observable sequence
112
*/
113
observable.withLatestFrom = function(...sources, resultSelector);
114
```
115
116
### Amb/Ambiguous (Static)
117
118
Returns the first observable to emit a value.
119
120
```javascript { .api }
121
/**
122
* Returns the first observable sequence to emit a value
123
* @param {...Observable} sources - Observable sequences to choose from
124
* @returns {Observable} First observable sequence to emit
125
*/
126
Rx.Observable.amb = function(...sources);
127
```
128
129
### Switch
130
131
Switches to the latest inner observable.
132
133
```javascript { .api }
134
/**
135
* Switches to the latest inner observable sequence
136
* @returns {Observable} Observable sequence switching to latest inner observable
137
*/
138
observable.switch = function();
139
```
140
141
### Start With
142
143
Prepends values to the observable sequence.
144
145
```javascript { .api }
146
/**
147
* Prepends values to the observable sequence
148
* @param {...*} values - Values to prepend
149
* @returns {Observable} Observable sequence with prepended values
150
*/
151
observable.startWith = function(...values);
152
```