|
21 | 21 |
|
22 | 22 | import java.util.ArrayList;
|
23 | 23 | import java.util.Arrays;
|
| 24 | +import java.util.Collection; |
24 | 25 | import java.util.List;
|
25 | 26 | import java.util.Map;
|
26 | 27 | import java.util.concurrent.CountDownLatch;
|
@@ -2688,6 +2689,119 @@ public R call(T0 t0, T1 t1, T2 t2, T3 t3) {
|
2688 | 2689 | });
|
2689 | 2690 | }
|
2690 | 2691 |
|
| 2692 | + /** |
| 2693 | + * Returns an Observable that emits the results of a function of your choosing applied to |
| 2694 | + * combinations of four items emitted, in sequence, by four other Observables. |
| 2695 | + * <p> |
| 2696 | + * <code>zip</code> applies this function in strict sequence, so the first item emitted by the |
| 2697 | + * new Observable will be the result of the function applied to the first item emitted by |
| 2698 | + * all of the Observalbes; the second item emitted by the new Observable will be the result of |
| 2699 | + * the function applied to the second item emitted by each of those Observables; and so forth. |
| 2700 | + * <p> |
| 2701 | + * The resulting <code>Observable<R></code> returned from <code>zip</code> will invoke |
| 2702 | + * <code>onNext</code> as many times as the number of <code>onNext</code> invokations of the |
| 2703 | + * source Observable that emits the fewest items. |
| 2704 | + * <p> |
| 2705 | + * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png"> |
| 2706 | + * |
| 2707 | + * @param ws |
| 2708 | + * An Observable of source Observables |
| 2709 | + * @param reduceFunction |
| 2710 | + * a function that, when applied to an item emitted by each of the source |
| 2711 | + * Observables, results in an item that will be emitted by the resulting Observable |
| 2712 | + * @return an Observable that emits the zipped results |
| 2713 | + */ |
| 2714 | + public static <R> Observable<R> zip(Observable<Observable<?>> ws, final FuncN<R> reduceFunction) { |
| 2715 | + return ws.toList().mapMany(new Func1<List<Observable<?>>, Observable<R>>() { |
| 2716 | + @Override |
| 2717 | + public Observable<R> call(List<Observable<?>> wsList) { |
| 2718 | + return create(OperationZip.zip(wsList, reduceFunction)); |
| 2719 | + } |
| 2720 | + }); |
| 2721 | + } |
| 2722 | + |
| 2723 | + /** |
| 2724 | + * Returns an Observable that emits the results of a function of your choosing applied to |
| 2725 | + * combinations of four items emitted, in sequence, by four other Observables. |
| 2726 | + * <p> |
| 2727 | + * <code>zip</code> applies this function in strict sequence, so the first item emitted by the |
| 2728 | + * new Observable will be the result of the function applied to the first item emitted by |
| 2729 | + * all of the Observalbes; the second item emitted by the new Observable will be the result of |
| 2730 | + * the function applied to the second item emitted by each of those Observables; and so forth. |
| 2731 | + * <p> |
| 2732 | + * The resulting <code>Observable<R></code> returned from <code>zip</code> will invoke |
| 2733 | + * <code>onNext</code> as many times as the number of <code>onNext</code> invocations of the |
| 2734 | + * source Observable that emits the fewest items. |
| 2735 | + * <p> |
| 2736 | + * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png"> |
| 2737 | + * |
| 2738 | + * @param ws |
| 2739 | + * An Observable of source Observables |
| 2740 | + * @param function |
| 2741 | + * a function that, when applied to an item emitted by each of the source |
| 2742 | + * Observables, results in an item that will be emitted by the resulting Observable |
| 2743 | + * @return an Observable that emits the zipped results |
| 2744 | + */ |
| 2745 | + public static <R> Observable<R> zip(Observable<Observable<?>> ws, final Object function) { |
| 2746 | + @SuppressWarnings({ "unchecked" }) |
| 2747 | + final FuncN<R> _f = Functions.from(function); |
| 2748 | + return zip(ws, _f); |
| 2749 | + } |
| 2750 | + |
| 2751 | + /** |
| 2752 | + * Returns an Observable that emits the results of a function of your choosing applied to |
| 2753 | + * combinations of four items emitted, in sequence, by four other Observables. |
| 2754 | + * <p> |
| 2755 | + * <code>zip</code> applies this function in strict sequence, so the first item emitted by the |
| 2756 | + * new Observable will be the result of the function applied to the first item emitted by |
| 2757 | + * all of the Observalbes; the second item emitted by the new Observable will be the result of |
| 2758 | + * the function applied to the second item emitted by each of those Observables; and so forth. |
| 2759 | + * <p> |
| 2760 | + * The resulting <code>Observable<R></code> returned from <code>zip</code> will invoke |
| 2761 | + * <code>onNext</code> as many times as the number of <code>onNext</code> invokations of the |
| 2762 | + * source Observable that emits the fewest items. |
| 2763 | + * <p> |
| 2764 | + * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png"> |
| 2765 | + * |
| 2766 | + * @param ws |
| 2767 | + * A collection of source Observables |
| 2768 | + * @param reduceFunction |
| 2769 | + * a function that, when applied to an item emitted by each of the source |
| 2770 | + * Observables, results in an item that will be emitted by the resulting Observable |
| 2771 | + * @return an Observable that emits the zipped results |
| 2772 | + */ |
| 2773 | + public static <R> Observable<R> zip(Collection<Observable<?>> ws, FuncN<R> reduceFunction) { |
| 2774 | + return create(OperationZip.zip(ws, reduceFunction)); |
| 2775 | + } |
| 2776 | + |
| 2777 | + /** |
| 2778 | + * Returns an Observable that emits the results of a function of your choosing applied to |
| 2779 | + * combinations of four items emitted, in sequence, by four other Observables. |
| 2780 | + * <p> |
| 2781 | + * <code>zip</code> applies this function in strict sequence, so the first item emitted by the |
| 2782 | + * new Observable will be the result of the function applied to the first item emitted by |
| 2783 | + * all of the Observalbes; the second item emitted by the new Observable will be the result of |
| 2784 | + * the function applied to the second item emitted by each of those Observables; and so forth. |
| 2785 | + * <p> |
| 2786 | + * The resulting <code>Observable<R></code> returned from <code>zip</code> will invoke |
| 2787 | + * <code>onNext</code> as many times as the number of <code>onNext</code> invocations of the |
| 2788 | + * source Observable that emits the fewest items. |
| 2789 | + * <p> |
| 2790 | + * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png"> |
| 2791 | + * |
| 2792 | + * @param ws |
| 2793 | + * A collection of source Observables |
| 2794 | + * @param function |
| 2795 | + * a function that, when applied to an item emitted by each of the source |
| 2796 | + * Observables, results in an item that will be emitted by the resulting Observable |
| 2797 | + * @return an Observable that emits the zipped results |
| 2798 | + */ |
| 2799 | + public static <R> Observable<R> zip(Collection<Observable<?>> ws, final Object function) { |
| 2800 | + @SuppressWarnings({ "unchecked" }) |
| 2801 | + final FuncN<R> _f = Functions.from(function); |
| 2802 | + return zip(ws, _f); |
| 2803 | + } |
| 2804 | + |
2691 | 2805 | /**
|
2692 | 2806 | * Filters an Observable by discarding any items it emits that do not meet some test.
|
2693 | 2807 | * <p>
|
|
0 commit comments