Writing basic RxCpp custom operators
In the previous section, we covered the topic of operator chaining. Operator chaining was possible because, the stock operators are implemented as part of the observable<T>
type. The operators that we are going to implement initially cannot be part of the operator chaining strategy. In this section, we will implement some RxCpp operators that can transform an Observable and return another Observable.
Writing an RxCpp operator as a function
To kickstart the discussion, let's write a simple operator that works on observable<string>. The operator just prepends the literal text Hello
before each item in the stream:
//----------- operatorSimple.cpp #include "rxcpp/rx.hpp" #include "rxcpp/rx-test.hpp" #include <iostream> namespace rxu=rxcpp::util; #include <array> using namespace rxcpp; using namespace rxcpp::operators; // Write a Simple Reactive operator Takes an Observable<string> and // Prefix Hello to every item and return...