Creating Observables from the scratch
So far, we have written code that create an Observable Stream from a range object or STL containers. Let's see how we can create an Observable Stream from the scratch. Well, almost:
// ObserverFromScratch.cpp #include "rxcpp/rx.hpp" #include "rxcpp/rx-test.hpp" int main() { auto ints = rxcpp::observable<>::create<int>( [](rxcpp::subscriber<int> s){ s.on_next(1); s.on_next(4); s.on_next(9); s.on_completed(); }); ints.subscribe( [](int v){printf("OnNext: %dn", v);}, [](){printf("OnCompletedn");}); }
The preceding program calls the on_ext
method to emit a series of numbers that are perfect squares. Those numbers (1,4,9) will be printed to the console.
Concatenating Observable Streams
We can concatenate two Streams to form a new Stream and this can be handy in some...