-
Notifications
You must be signed in to change notification settings - Fork 7.6k
/
Observable.java
10360 lines (9913 loc) · 540 KB
/
Observable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/
package rx;
import static rx.functions.Functions.alwaysFalse;
import java.util.*;
import java.util.concurrent.*;
import rx.exceptions.*;
import rx.functions.*;
import rx.internal.operators.*;
import rx.internal.util.ScalarSynchronousObservable;
import rx.observables.*;
import rx.observers.SafeSubscriber;
import rx.plugins.*;
import rx.schedulers.*;
import rx.subjects.*;
import rx.subscriptions.Subscriptions;
/**
* The Observable class that implements the Reactive Pattern.
* <p>
* This class provides methods for subscribing to the Observable as well as delegate methods to the various
* Observers.
* <p>
* The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
* <p>
* <img width="640" height="301" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/legend.png" alt="">
* <p>
* For more information see the <a href="https://github.com/Netflix/RxJava/wiki/Observable">RxJava wiki</a>
*
* @param <T>
* the type of the items emitted by the Observable
*/
public class Observable<T> {
final OnSubscribe<T> onSubscribe;
/**
* Creates an Observable with a Function to execute when it is subscribed to.
* <p>
* <em>Note:</em> Use {@link #create(OnSubscribe)} to create an Observable, instead of this constructor,
* unless you specifically have a need for inheritance.
*
* @param f
* {@link OnSubscribe} to be executed when {@link #subscribe(Subscriber)} is called
*/
protected Observable(OnSubscribe<T> f) {
this.onSubscribe = f;
}
private static final RxJavaObservableExecutionHook hook = RxJavaPlugins.getInstance().getObservableExecutionHook();
/**
* Returns an Observable that will execute the specified function when a {@link Subscriber} subscribes to
* it.
* <p>
* <img width="640" height="200" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/create.png" alt="">
* <p>
* Write the function you pass to {@code create} so that it behaves as an Observable: It should invoke the
* Subscriber's {@link Subscriber#onNext onNext}, {@link Subscriber#onError onError}, and
* {@link Subscriber#onCompleted onCompleted} methods appropriately.
* <p>
* A well-formed Observable must invoke either the Subscriber's {@code onCompleted} method exactly once or
* its {@code onError} method exactly once.
* <p>
* See <a href="http://go.microsoft.com/fwlink/?LinkID=205219">Rx Design Guidelines (PDF)</a> for detailed
* information.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code create} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param <T>
* the type of the items that this Observable emits
* @param f
* a function that accepts an {@code Subscriber<T>}, and invokes its {@code onNext},
* {@code onError}, and {@code onCompleted} methods as appropriate
* @return an Observable that, when a {@link Subscriber} subscribes to it, will execute the specified
* function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Creating-Observables#create">RxJava wiki: create</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.create.aspx">MSDN: Observable.Create</a>
*/
public final static <T> Observable<T> create(OnSubscribe<T> f) {
return new Observable<T>(hook.onCreate(f));
}
/**
* Invoked when Obserable.subscribe is called.
*/
public static interface OnSubscribe<T> extends Action1<Subscriber<? super T>> {
// cover for generics insanity
}
/**
* Operator function for lifting into an Observable.
*/
public interface Operator<R, T> extends Func1<Subscriber<? super R>, Subscriber<? super T>> {
// cover for generics insanity
}
/**
* @deprecated use {@link #create(OnSubscribe)}
*/
@Deprecated
public final static <T> Observable<T> create(final OnSubscribeFunc<T> f) {
return new Observable<T>(new OnSubscribe<T>() {
@Override
public void call(Subscriber<? super T> observer) {
Subscription s = f.onSubscribe(observer);
if (s != null && s != observer) {
observer.add(s);
}
}
});
}
/**
* @deprecated use {@link OnSubscribe}
*/
@Deprecated
public static interface OnSubscribeFunc<T> extends Function {
public Subscription onSubscribe(Observer<? super T> op);
}
/**
* Lifts a function to the current Observable and returns a new Observable that when subscribed to will pass
* the values of the current Observable through the Operator function.
* <p>
* In other words, this allows chaining Observers together on an Observable for acting on the values within
* the Observable.
* <p> {@code
* observable.map(...).filter(...).take(5).lift(new OperatorA()).lift(new OperatorB(...)).subscribe()
* }
* <p>
* If the operator you are creating is designed to act on the individual items emitted by a source
* Observable, use {@code lift}. If your operator is designed to transform the source Observable as a whole
* (for instance, by applying a particular set of existing RxJava operators to it) use {@link #compose}.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code lift} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param lift the Operator that implements the Observable-operating function to be applied to the source
* Observable
* @return an Observable that is the result of applying the lifted Operator to the source Observable
* @see <a href="https://github.com/Netflix/RxJava/wiki/Implementing-Your-Own-Operators">RxJava wiki: Implementing Your Own Operators</a>
* @since 0.17
*/
public final <R> Observable<R> lift(final Operator<? extends R, ? super T> lift) {
return new Observable<R>(new OnSubscribe<R>() {
@Override
public void call(Subscriber<? super R> o) {
try {
Subscriber<? super T> st = hook.onLift(lift).call(o);
// new Subscriber created and being subscribed with so 'onStart' it
st.onStart();
onSubscribe.call(st);
} catch (Throwable e) {
// localized capture of errors rather than it skipping all operators
// and ending up in the try/catch of the subscribe method which then
// prevents onErrorResumeNext and other similar approaches to error handling
if (e instanceof OnErrorNotImplementedException) {
throw (OnErrorNotImplementedException) e;
}
o.onError(e);
}
}
});
}
/**
* Transform an Observable by applying a particular Transformer function to it.
* <p>
* This method operates on the Observable itself whereas {@link #lift} operates on the Observable's
* Subscribers or Observers.
* <p>
* If the operator you are creating is designed to act on the individual items emitted by a source
* Observable, use {@link #lift}. If your operator is designed to transform the source Observable as a whole
* (for instance, by applying a particular set of existing RxJava operators to it) use {@code compose}.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code compose} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param transformer implements the function that transforms the source Observable
* @return the source Observable, transformed by the transformer function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Implementing-Your-Own-Operators">RxJava wiki: Implementing Your Own Operators</a>
* @since 0.20
*/
public <R> Observable<R> compose(Transformer<? super T, R> transformer) {
return transformer.call(this);
}
/**
* Transformer function used by {@link #compose}.
* @warn more complete description needed
* @since 0.20
*/
public static interface Transformer<T, R> extends Func1<Observable<? extends T>, Observable<R>> {
// cover for generics insanity
}
/* *********************************************************************************************************
* Operators Below Here
* *********************************************************************************************************
*/
/**
* Mirrors the one Observable in an Iterable of several Observables that first emits an item.
* <p>
* <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param sources
* an Iterable of Observable sources competing to react first
* @return an Observable that emits the same sequence of items as whichever of the source Observables first
* emitted an item
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229115.aspx">MSDN: Observable.Amb</a>
*/
public final static <T> Observable<T> amb(Iterable<? extends Observable<? extends T>> sources) {
return create(OnSubscribeAmb.amb(sources));
}
/**
* Given two Observables, mirrors the one that first emits an item.
* <p>
* <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* an Observable competing to react first
* @param o2
* an Observable competing to react first
* @return an Observable that emits the same sequence of items as whichever of the source Observables first
* emitted an item
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229733.aspx">MSDN: Observable.Amb</a>
*/
public final static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2) {
return create(OnSubscribeAmb.amb(o1, o2));
}
/**
* Given three Observables, mirrors the one that first emits an item.
* <p>
* <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* an Observable competing to react first
* @param o2
* an Observable competing to react first
* @param o3
* an Observable competing to react first
* @return an Observable that emits the same sequence of items as whichever of the source Observables first
* emitted an item
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229733.aspx">MSDN: Observable.Amb</a>
*/
public final static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3) {
return create(OnSubscribeAmb.amb(o1, o2, o3));
}
/**
* Given four Observables, mirrors the one that first emits an item.
* <p>
* <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* an Observable competing to react first
* @param o2
* an Observable competing to react first
* @param o3
* an Observable competing to react first
* @param o4
* an Observable competing to react first
* @return an Observable that emits the same sequence of items as whichever of the source Observables first
* emitted an item
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229733.aspx">MSDN: Observable.Amb</a>
*/
public final static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4) {
return create(OnSubscribeAmb.amb(o1, o2, o3, o4));
}
/**
* Given five Observables, mirrors the one that first emits an item.
* <p>
* <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* an Observable competing to react first
* @param o2
* an Observable competing to react first
* @param o3
* an Observable competing to react first
* @param o4
* an Observable competing to react first
* @param o5
* an Observable competing to react first
* @return an Observable that emits the same sequence of items as whichever of the source Observables first
* emitted an item
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229733.aspx">MSDN: Observable.Amb</a>
*/
public final static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5) {
return create(OnSubscribeAmb.amb(o1, o2, o3, o4, o5));
}
/**
* Given six Observables, mirrors the one that first emits an item.
* <p>
* <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* an Observable competing to react first
* @param o2
* an Observable competing to react first
* @param o3
* an Observable competing to react first
* @param o4
* an Observable competing to react first
* @param o5
* an Observable competing to react first
* @param o6
* an Observable competing to react first
* @return an Observable that emits the same sequence of items as whichever of the source Observables first
* emitted an item
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229733.aspx">MSDN: Observable.Amb</a>
*/
public final static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5, Observable<? extends T> o6) {
return create(OnSubscribeAmb.amb(o1, o2, o3, o4, o5, o6));
}
/**
* Given seven Observables, mirrors the one that first emits an item.
* <p>
* <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* an Observable competing to react first
* @param o2
* an Observable competing to react first
* @param o3
* an Observable competing to react first
* @param o4
* an Observable competing to react first
* @param o5
* an Observable competing to react first
* @param o6
* an Observable competing to react first
* @param o7
* an Observable competing to react first
* @return an Observable that emits the same sequence of items as whichever of the source Observables first
* emitted an item
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229733.aspx">MSDN: Observable.Amb</a>
*/
public final static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5, Observable<? extends T> o6, Observable<? extends T> o7) {
return create(OnSubscribeAmb.amb(o1, o2, o3, o4, o5, o6, o7));
}
/**
* Given eight Observables, mirrors the one that first emits an item.
* <p>
* <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* an Observable competing to react first
* @param o2
* an Observable competing to react first
* @param o3
* an Observable competing to react first
* @param o4
* an Observable competing to react first
* @param o5
* an Observable competing to react first
* @param o6
* an Observable competing to react first
* @param o7
* an Observable competing to react first
* @param o8
* an observable competing to react first
* @return an Observable that emits the same sequence of items as whichever of the source Observables first
* emitted an item
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229733.aspx">MSDN: Observable.Amb</a>
*/
public final static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5, Observable<? extends T> o6, Observable<? extends T> o7, Observable<? extends T> o8) {
return create(OnSubscribeAmb.amb(o1, o2, o3, o4, o5, o6, o7, o8));
}
/**
* Given nine Observables, mirrors the one that first emits an item.
* <p>
* <img width="640" height="385" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/amb.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code amb} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* an Observable competing to react first
* @param o2
* an Observable competing to react first
* @param o3
* an Observable competing to react first
* @param o4
* an Observable competing to react first
* @param o5
* an Observable competing to react first
* @param o6
* an Observable competing to react first
* @param o7
* an Observable competing to react first
* @param o8
* an Observable competing to react first
* @param o9
* an Observable competing to react first
* @return an Observable that emits the same sequence of items as whichever of the source Observables first
* emitted an item
* @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#amb">RxJava wiki: amb</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229733.aspx">MSDN: Observable.Amb</a>
*/
public final static <T> Observable<T> amb(Observable<? extends T> o1, Observable<? extends T> o2, Observable<? extends T> o3, Observable<? extends T> o4, Observable<? extends T> o5, Observable<? extends T> o6, Observable<? extends T> o7, Observable<? extends T> o8, Observable<? extends T> o9) {
return create(OnSubscribeAmb.amb(o1, o2, o3, o4, o5, o6, o7, o8, o9));
}
/**
* Combines two source Observables by emitting an item that aggregates the latest values of each of the
* source Observables each time an item is received from either of the source Observables, where this
* aggregation is defined by a specified function.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/combineLatest.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code combineLatest} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* the first source Observable
* @param o2
* the second source Observable
* @param combineFunction
* the aggregation function used to combine the items emitted by the source Observables
* @return an Observable that emits items that are the result of combining the items emitted by the source
* Observables by means of the given aggregation function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#combinelatest">RxJava wiki: combineLatest</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211991.aspx">MSDN: Observable.CombineLatest</a>
*/
@SuppressWarnings("unchecked")
public static final <T1, T2, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Func2<? super T1, ? super T2, ? extends R> combineFunction) {
return combineLatest(Arrays.asList(o1, o2), Functions.fromFunc(combineFunction));
}
/**
* Combines three source Observables by emitting an item that aggregates the latest values of each of the
* source Observables each time an item is received from any of the source Observables, where this
* aggregation is defined by a specified function.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/combineLatest.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code combineLatest} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* the first source Observable
* @param o2
* the second source Observable
* @param o3
* the third source Observable
* @param combineFunction
* the aggregation function used to combine the items emitted by the source Observables
* @return an Observable that emits items that are the result of combining the items emitted by the source
* Observables by means of the given aggregation function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#combinelatest">RxJava wiki: combineLatest</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211991.aspx">MSDN: Observable.CombineLatest</a>
*/
@SuppressWarnings("unchecked")
public static final <T1, T2, T3, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Func3<? super T1, ? super T2, ? super T3, ? extends R> combineFunction) {
return combineLatest(Arrays.asList(o1, o2, o3), Functions.fromFunc(combineFunction));
}
/**
* Combines four source Observables by emitting an item that aggregates the latest values of each of the
* source Observables each time an item is received from any of the source Observables, where this
* aggregation is defined by a specified function.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/combineLatest.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code combineLatest} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* the first source Observable
* @param o2
* the second source Observable
* @param o3
* the third source Observable
* @param o4
* the fourth source Observable
* @param combineFunction
* the aggregation function used to combine the items emitted by the source Observables
* @return an Observable that emits items that are the result of combining the items emitted by the source
* Observables by means of the given aggregation function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#combinelatest">RxJava wiki: combineLatest</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211991.aspx">MSDN: Observable.CombineLatest</a>
*/
@SuppressWarnings("unchecked")
public static final <T1, T2, T3, T4, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4,
Func4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> combineFunction) {
return combineLatest(Arrays.asList(o1, o2, o3, o4), Functions.fromFunc(combineFunction));
}
/**
* Combines five source Observables by emitting an item that aggregates the latest values of each of the
* source Observables each time an item is received from any of the source Observables, where this
* aggregation is defined by a specified function.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/combineLatest.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code combineLatest} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* the first source Observable
* @param o2
* the second source Observable
* @param o3
* the third source Observable
* @param o4
* the fourth source Observable
* @param o5
* the fifth source Observable
* @param combineFunction
* the aggregation function used to combine the items emitted by the source Observables
* @return an Observable that emits items that are the result of combining the items emitted by the source
* Observables by means of the given aggregation function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#combinelatest">RxJava wiki: combineLatest</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211991.aspx">MSDN: Observable.CombineLatest</a>
*/
@SuppressWarnings("unchecked")
public static final <T1, T2, T3, T4, T5, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5,
Func5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> combineFunction) {
return combineLatest(Arrays.asList(o1, o2, o3, o4, o5), Functions.fromFunc(combineFunction));
}
/**
* Combines six source Observables by emitting an item that aggregates the latest values of each of the
* source Observables each time an item is received from any of the source Observables, where this
* aggregation is defined by a specified function.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/combineLatest.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code combineLatest} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* the first source Observable
* @param o2
* the second source Observable
* @param o3
* the third source Observable
* @param o4
* the fourth source Observable
* @param o5
* the fifth source Observable
* @param o6
* the sixth source Observable
* @param combineFunction
* the aggregation function used to combine the items emitted by the source Observables
* @return an Observable that emits items that are the result of combining the items emitted by the source
* Observables by means of the given aggregation function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#combinelatest">RxJava wiki: combineLatest</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211991.aspx">MSDN: Observable.CombineLatest</a>
*/
@SuppressWarnings("unchecked")
public static final <T1, T2, T3, T4, T5, T6, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6,
Func6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> combineFunction) {
return combineLatest(Arrays.asList(o1, o2, o3, o4, o5, o6), Functions.fromFunc(combineFunction));
}
/**
* Combines seven source Observables by emitting an item that aggregates the latest values of each of the
* source Observables each time an item is received from any of the source Observables, where this
* aggregation is defined by a specified function.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/combineLatest.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code combineLatest} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* the first source Observable
* @param o2
* the second source Observable
* @param o3
* the third source Observable
* @param o4
* the fourth source Observable
* @param o5
* the fifth source Observable
* @param o6
* the sixth source Observable
* @param o7
* the seventh source Observable
* @param combineFunction
* the aggregation function used to combine the items emitted by the source Observables
* @return an Observable that emits items that are the result of combining the items emitted by the source
* Observables by means of the given aggregation function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#combinelatest">RxJava wiki: combineLatest</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211991.aspx">MSDN: Observable.CombineLatest</a>
*/
@SuppressWarnings("unchecked")
public static final <T1, T2, T3, T4, T5, T6, T7, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Observable<? extends T7> o7,
Func7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> combineFunction) {
return combineLatest(Arrays.asList(o1, o2, o3, o4, o5, o6, o7), Functions.fromFunc(combineFunction));
}
/**
* Combines eight source Observables by emitting an item that aggregates the latest values of each of the
* source Observables each time an item is received from any of the source Observables, where this
* aggregation is defined by a specified function.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/combineLatest.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code combineLatest} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* the first source Observable
* @param o2
* the second source Observable
* @param o3
* the third source Observable
* @param o4
* the fourth source Observable
* @param o5
* the fifth source Observable
* @param o6
* the sixth source Observable
* @param o7
* the seventh source Observable
* @param o8
* the eighth source Observable
* @param combineFunction
* the aggregation function used to combine the items emitted by the source Observables
* @return an Observable that emits items that are the result of combining the items emitted by the source
* Observables by means of the given aggregation function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#combinelatest">RxJava wiki: combineLatest</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211991.aspx">MSDN: Observable.CombineLatest</a>
*/
@SuppressWarnings("unchecked")
public static final <T1, T2, T3, T4, T5, T6, T7, T8, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Observable<? extends T7> o7, Observable<? extends T8> o8,
Func8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> combineFunction) {
return combineLatest(Arrays.asList(o1, o2, o3, o4, o5, o6, o7, o8), Functions.fromFunc(combineFunction));
}
/**
* Combines nine source Observables by emitting an item that aggregates the latest values of each of the
* source Observables each time an item is received from any of the source Observables, where this
* aggregation is defined by a specified function.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/combineLatest.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code combineLatest} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param o1
* the first source Observable
* @param o2
* the second source Observable
* @param o3
* the third source Observable
* @param o4
* the fourth source Observable
* @param o5
* the fifth source Observable
* @param o6
* the sixth source Observable
* @param o7
* the seventh source Observable
* @param o8
* the eighth source Observable
* @param o9
* the ninth source Observable
* @param combineFunction
* the aggregation function used to combine the items emitted by the source Observables
* @return an Observable that emits items that are the result of combining the items emitted by the source
* Observables by means of the given aggregation function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#combinelatest">RxJava wiki: combineLatest</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211991.aspx">MSDN: Observable.CombineLatest</a>
*/
@SuppressWarnings("unchecked")
public static final <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Observable<R> combineLatest(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Observable<? extends T4> o4, Observable<? extends T5> o5, Observable<? extends T6> o6, Observable<? extends T7> o7, Observable<? extends T8> o8,
Observable<? extends T9> o9,
Func9<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> combineFunction) {
return combineLatest(Arrays.asList(o1, o2, o3, o4, o5, o6, o7, o8, o9), Functions.fromFunc(combineFunction));
}
/**
* Combines a list of source Observables by emitting an item that aggregates the latest values of each of
* the source Observables each time an item is received from any of the source Observables, where this
* aggregation is defined by a specified function.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code combineLatest} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param <T>
* the common base type of source values
* @param <R>
* the result type
* @param sources
* the list of source Observables
* @param combineFunction
* the aggregation function used to combine the items emitted by the source Observables
* @return an Observable that emits items that are the result of combining the items emitted by the source
* Observables by means of the given aggregation function
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#combinelatest">RxJava wiki: combineLatest</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211991.aspx">MSDN: Observable.CombineLatest</a>
*/
public static final <T, R> Observable<R> combineLatest(List<? extends Observable<? extends T>> sources, FuncN<? extends R> combineFunction) {
return create(new OnSubscribeCombineLatest<T, R>(sources, combineFunction));
}
/**
* Returns an Observable that emits the items emitted by each of the Observables emitted by the source
* Observable, one after the other, without interleaving them.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param observables
* an Observable that emits Observables
* @return an Observable that emits items all of the items emitted by the Observables emitted by
* {@code observables}, one after the other, without interleaving them
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-and-Aggregate-Operators#concat">RxJava wiki: concat</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat.aspx">MSDN: Observable.Concat</a>
*/
public final static <T> Observable<T> concat(Observable<? extends Observable<? extends T>> observables) {
return observables.lift(new OperatorConcat<T>());
}
/**
* Returns an Observable that emits the items emitted by two Observables, one after the other, without
* interleaving them.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @return an Observable that emits items emitted by the two source Observables, one after the other,
* without interleaving them
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-and-Aggregate-Operators#concat">RxJava wiki: concat</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat.aspx">MSDN: Observable.Concat</a>
*/
public final static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2) {
return concat(just(t1, t2));
}
/**
* Returns an Observable that emits the items emitted by three Observables, one after the other, without
* interleaving them.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @return an Observable that emits items emitted by the three source Observables, one after the other,
* without interleaving them
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-and-Aggregate-Operators#concat">RxJava wiki: concat</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat.aspx">MSDN: Observable.Concat</a>
*/
public final static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3) {
return concat(just(t1, t2, t3));
}
/**
* Returns an Observable that emits the items emitted by four Observables, one after the other, without
* interleaving them.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @return an Observable that emits items emitted by the four source Observables, one after the other,
* without interleaving them
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-and-Aggregate-Operators#concat">RxJava wiki: concat</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat.aspx">MSDN: Observable.Concat</a>
*/
public final static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4) {
return concat(just(t1, t2, t3, t4));
}
/**
* Returns an Observable that emits the items emitted by five Observables, one after the other, without
* interleaving them.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @param t5
* an Observable to be concatenated
* @return an Observable that emits items emitted by the five source Observables, one after the other,
* without interleaving them
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-and-Aggregate-Operators#concat">RxJava wiki: concat</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat.aspx">MSDN: Observable.Concat</a>
*/
public final static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5) {
return concat(just(t1, t2, t3, t4, t5));
}
/**
* Returns an Observable that emits the items emitted by six Observables, one after the other, without
* interleaving them.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @param t5
* an Observable to be concatenated
* @param t6
* an Observable to be concatenated
* @return an Observable that emits items emitted by the six source Observables, one after the other,
* without interleaving them
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-and-Aggregate-Operators#concat">RxJava wiki: concat</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat.aspx">MSDN: Observable.Concat</a>
*/
public final static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6) {
return concat(just(t1, t2, t3, t4, t5, t6));
}
/**
* Returns an Observable that emits the items emitted by seven Observables, one after the other, without
* interleaving them.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @param t5
* an Observable to be concatenated
* @param t6
* an Observable to be concatenated
* @param t7
* an Observable to be concatenated
* @return an Observable that emits items emitted by the seven source Observables, one after the other,
* without interleaving them
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-and-Aggregate-Operators#concat">RxJava wiki: concat</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat.aspx">MSDN: Observable.Concat</a>
*/
public final static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7) {
return concat(just(t1, t2, t3, t4, t5, t6, t7));
}
/**
* Returns an Observable that emits the items emitted by eight Observables, one after the other, without
* interleaving them.
* <p>
* <img width="640" height="380" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @param t5
* an Observable to be concatenated
* @param t6
* an Observable to be concatenated
* @param t7
* an Observable to be concatenated
* @param t8
* an Observable to be concatenated
* @return an Observable that emits items emitted by the eight source Observables, one after the other,
* without interleaving them
* @see <a href="https://github.com/Netflix/RxJava/wiki/Mathematical-and-Aggregate-Operators#concat">RxJava wiki: concat</a>