1
- import { CombineSignature , InternalListener , Operator , Stream } from '../core' ;
1
+ import { InternalListener , Operator , Stream } from '../core' ;
2
+
3
+ export interface SampleCombineSignature {
4
+ ( ) : < T > ( s : Stream < T > ) => Stream < [ T ] > ;
5
+ < T1 > ( s1 : Stream < T1 > ) : < T > ( s : Stream < T > ) => Stream < [ T , T1 ] > ;
6
+ < T1 , T2 > (
7
+ s1 : Stream < T1 > ,
8
+ s2 : Stream < T2 > ) : < T > ( s : Stream < T > ) => Stream < [ T , T1 , T2 ] > ;
9
+ < T1 , T2 , T3 > (
10
+ s1 : Stream < T1 > ,
11
+ s2 : Stream < T2 > ,
12
+ s3 : Stream < T3 > ) : < T > ( s : Stream < T > ) => Stream < [ T , T1 , T2 , T3 ] > ;
13
+ < T1 , T2 , T3 , T4 > (
14
+ s1 : Stream < T1 > ,
15
+ s2 : Stream < T2 > ,
16
+ s3 : Stream < T3 > ,
17
+ s4 : Stream < T4 > ) : < T > ( s : Stream < T > ) => Stream < [ T , T1 , T2 , T3 , T4 ] > ;
18
+ < T1 , T2 , T3 , T4 , T5 > (
19
+ s1 : Stream < T1 > ,
20
+ s2 : Stream < T2 > ,
21
+ s3 : Stream < T3 > ,
22
+ s4 : Stream < T4 > ,
23
+ s5 : Stream < T5 > ) : < T > ( s : Stream < T > ) => Stream < [ T , T1 , T2 , T3 , T4 , T5 ] > ;
24
+ < T1 , T2 , T3 , T4 , T5 , T6 > (
25
+ s1 : Stream < T1 > ,
26
+ s2 : Stream < T2 > ,
27
+ s3 : Stream < T3 > ,
28
+ s4 : Stream < T4 > ,
29
+ s5 : Stream < T5 > ,
30
+ s6 : Stream < T6 > ) : < T > ( s : Stream < T > ) => Stream < [ T , T1 , T2 , T3 , T4 , T5 , T6 ] > ;
31
+ < T1 , T2 , T3 , T4 , T5 , T6 , T7 > (
32
+ s1 : Stream < T1 > ,
33
+ s2 : Stream < T2 > ,
34
+ s3 : Stream < T3 > ,
35
+ s4 : Stream < T4 > ,
36
+ s5 : Stream < T5 > ,
37
+ s6 : Stream < T6 > ,
38
+ s7 : Stream < T7 > ) : < T > ( s : Stream < T > ) => Stream < [ T , T1 , T2 , T3 , T4 , T5 , T6 , T7 ] > ;
39
+ < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 > (
40
+ s1 : Stream < T1 > ,
41
+ s2 : Stream < T2 > ,
42
+ s3 : Stream < T3 > ,
43
+ s4 : Stream < T4 > ,
44
+ s5 : Stream < T5 > ,
45
+ s6 : Stream < T6 > ,
46
+ s7 : Stream < T7 > ,
47
+ s8 : Stream < T8 > ) : < T > ( s : Stream < T > ) => Stream < [ T , T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 ] > ;
48
+ ( ...streams : Array < Stream < any > > ) : ( s : Stream < any > ) => Stream < Array < any > > ;
49
+ }
2
50
3
51
export class SampleCombineListener < T > implements InternalListener < T > {
4
52
constructor ( private i : number , private p : SampleCombineOperator < any > ) {
@@ -75,6 +123,13 @@ export class SampleCombineOperator<T> implements Operator<T, Array<any>> {
75
123
}
76
124
}
77
125
126
+ let sampleCombine : SampleCombineSignature ;
127
+ sampleCombine = function sampleCombine ( ...streams : Array < Stream < any > > ) {
128
+ return function sampleCombineOperator ( sampler : Stream < any > ) : Stream < Array < any > > {
129
+ return new Stream < Array < any > > ( new SampleCombineOperator ( sampler , streams ) ) ;
130
+ } ;
131
+ } as SampleCombineSignature ;
132
+
78
133
/**
79
134
* Combines a source stream with multiple other streams. The result stream
80
135
* will emit the latest events from all input streams, but only when the
@@ -90,10 +145,10 @@ export class SampleCombineOperator<T> implements Operator<T, Array<any>> {
90
145
* Marble diagram:
91
146
*
92
147
* ```text
93
- * --1----2-----3--------4---
94
- * ----a-----b-----c--d------
148
+ * --1----2-----3--------4--- (source)
149
+ * ----a-----b-----c--d------ (other)
95
150
* sampleCombine
96
- * --1? ---2a----3b-------4d--
151
+ * ---- ---2a----3b-------4d--
97
152
* ```
98
153
*
99
154
* Examples:
@@ -105,7 +160,7 @@ export class SampleCombineOperator<T> implements Operator<T, Array<any>> {
105
160
* const sampler = xs.periodic(1000).take(3)
106
161
* const other = xs.periodic(100)
107
162
*
108
- * const stream = sampleCombine(sampler, other)
163
+ * const stream = sampler.compose( sampleCombine(other) )
109
164
*
110
165
* stream.addListener({
111
166
* next: i => console.log(i),
@@ -127,7 +182,7 @@ export class SampleCombineOperator<T> implements Operator<T, Array<any>> {
127
182
* const sampler = xs.periodic(1000).take(3)
128
183
* const other = xs.periodic(100).take(2)
129
184
*
130
- * const stream = sampleCombine(sampler, other)
185
+ * const stream = sampler.compose( sampleCombine(other) )
131
186
*
132
187
* stream.addListener({
133
188
* next: i => console.log(i),
@@ -142,14 +197,8 @@ export class SampleCombineOperator<T> implements Operator<T, Array<any>> {
142
197
* > [2, 1]
143
198
* ```
144
199
*
145
- * @param {Stream } sampler The source stream of which to sample.
146
- * @param { ...Stream } streams One or more streams to combine .
200
+ * @param {... Stream } streams One or more streams to combine with the sampler
201
+ * stream .
147
202
* @return {Stream }
148
203
*/
149
- let sampleCombine : CombineSignature ;
150
- sampleCombine = function ( sampler : Stream < any > ,
151
- ...streams : Array < Stream < any > > ) : Stream < Array < any > > {
152
- return new Stream < Array < any > > ( new SampleCombineOperator < any > ( sampler , streams ) ) ;
153
- } as CombineSignature ;
154
-
155
- export default sampleCombine ;
204
+ export default sampleCombine ;
0 commit comments