Bring by one item from all given observables and select a value to emit from the new observable that is returned.
More...
Bring by one item from all given observables and select a value to emit from the new observable that is returned.
- Template Parameters
-
AN | types of scheduler (optional), aggregate function (optional), and source observables |
- Parameters
-
an | scheduler (optional), aggregation function (optional), and source observables |
- Returns
- Observable that emits the result of combining the items emitted and brought by one from each of the source observables.
If scheduler is omitted, identity_current_thread is used.
If aggregation function is omitted, the resulting observable returns tuples of emitted items.
- Sample Code
Neither scheduler nor aggregation function are present:
auto values = o1.zip(o2, o3);
values.
[](std::tuple<int, int, int> v){printf("OnNext: %d, %d, %d\n", std::get<0>(v), std::get<1>(v), std::get<2>(v));},
[](){printf("OnCompleted\n");});
OnNext: 1, 1, 1
OnNext: 2, 2, 2
OnNext: 3, 3, 3
OnCompleted
Only scheduler is present:
printf("[thread %s] Start task\n", get_pid().c_str());
printf("[thread %s] Source1 OnNext: %d\n", get_pid().c_str(), v);
return v;
});
printf("[thread %s] Source2 OnNext: %d\n", get_pid().c_str(), v);
return v;
});
printf("[thread %s] Source3 OnNext: %d\n", get_pid().c_str(), v);
return v;
});
auto values = o1.zip(thr, o2, o3);
values.
[](std::tuple<int, int, int> v){printf("[thread %s] OnNext: %d, %d, %d\n", get_pid().c_str(), std::get<0>(v), std::get<1>(v), std::get<2>(v));},
[](){printf("[thread %s] OnCompleted\n", get_pid().c_str());});
printf("[thread %s] Finish task\n", get_pid().c_str());
[thread 47481267428736] Start task
[thread 47481267428736] Source1 OnNext: 1
[thread 47481267428736] Source2 OnNext: 1
[thread 47481267428736] Source3 OnNext: 1
[thread 47481298978560] OnNext: 1, 1, 1
[thread 47481267428736] Source1 OnNext: 2
[thread 47481267428736] Source1 OnNext: 3
[thread 47481267428736] Source2 OnNext: 2
[thread 47481267428736] Source1 OnNext: 4
[thread 47481267428736] Source3 OnNext: 2
[thread 47481298978560] OnNext: 2, 2, 2
[thread 47481267428736] Source1 OnNext: 5
[thread 47481267428736] Source2 OnNext: 3
[thread 47481267428736] Source1 OnNext: 6
[thread 47481267428736] Source1 OnNext: 7
[thread 47481267428736] Source2 OnNext: 4
[thread 47481267428736] Source3 OnNext: 3
[thread 47481298978560] OnNext: 3, 3, 3
[thread 47481298978560] OnCompleted
[thread 47481267428736] Finish task
Only aggregation function is present:
[](int v1, int v2, int v3) {
return 100 * v1 + 10 * v2 + v3;
},
o2, o3);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 111
OnNext: 222
OnNext: 333
OnCompleted
Both scheduler and aggregation function are present:
auto values = o1.zip(
[](int v1, int v2, int v3) {
return 100 * v1 + 10 * v2 + v3;
},
o2, o3);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 111
OnNext: 222
OnNext: 333
OnCompleted