ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.03k stars 390 forks source link

How to use operators on a list of Observables #520

Closed ghost closed 4 years ago

ghost commented 4 years ago

hello, i'm a little new to cpp and rxCpp community, i was wondering if i could perform operators on a dynamic number of observables. it seems that these operators only accept Variadic arguments, which i couldn't work dynamically with. to elaborate my problem with an example, how to merge a std::list of observables? Thanks in advance.

kirkshoop commented 4 years ago

Hi!

take a look at the examples for iterate

for example, this would iterate over a container of observables.

    std::array< rxcpp::observable<int>, 3 > a={{rxcpp::just(1), rxcpp::just(2), rxcpp::just(3)}};
    auto values = rxcpp::observable<>::iterate(a);
    values.
        merge().
        subscribe(
            [](int v){printf("OnNext: %d\n", v);},
            [](){printf("OnCompleted\n");});