Creating Observables from scratch
So far, we have written programs that create an Observable Stream from a range object or STL containers. Let's see how we can create an Observable Stream from 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 next method to emit a series of numbers that are perfect squares. Those numbers 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 cases. Let's see how this works by writing a simple program:
//------------- Concactatenate...