The Reactive Extensions for C++ (RxCpp) is a library of algorithms for values-distributed-in-time. The
library does the same for values-distributed-in-space.
TaskStatusrxcpp CI
SourceBadgesGithub
Gitter.im
Packages
Documentation
Usage
RxCpp is a header-only C++ library that only depends on the standard library. The CMake build generates documentation and unit tests. The unit tests depend on a git submodule for the
library.
Example
Add Rx/v2/src to the include paths
#include"rxcpp/rx.hpp"namespaceRx { usingnamespacerxcpp;usingnamespacerxcpp::sources;usingnamespacerxcpp::operators;usingnamespacerxcpp::util; } usingnamespaceRx; #include<regex> #include<random>usingnamespacestd;usingnamespacestd::chrono;intmain() { random_device rd; // non-deterministic generator mt19937 gen(rd()); uniform_int_distribution<> dist(4, 18); // for testing purposes, produce byte stream that from lines of textauto bytes = range(0, 10) | flat_map([&](int i){ auto body = from((uint8_t)('A' + i)) | repeat(dist(gen)) | as_dynamic(); auto delim = from((uint8_t)'\r'); returnfrom(body, delim) | concat(); }) | window(17) | flat_map([](observable<uint8_t> w){ return w | reduce( vector<uint8_t>(), [](vector<uint8_t> v, uint8_t b){ v.push_back(b); return v; }) | as_dynamic(); }) | tap([](const vector<uint8_t>& v){ // print input packet of bytescopy(v.begin(), v.end(), ostream_iterator<long>(cout, "")); cout << endl; }); //// recover lines of text from byte stream//auto removespaces = [](string s){ s.erase(remove_if(s.begin(), s.end(), ::isspace), s.end()); return s; }; // create strings split on \rauto strings = bytes | concat_map([](vector<uint8_t> v){ string s(v.begin(), v.end()); regex delim(R"/(\r)/"); cregex_token_iterator cursor(&s[0], &s[0] + s.size(), delim, {-1, 0}); cregex_token_iterator end; vector<string> splits(cursor, end); return iterate(move(splits)); }) | filter([](const string& s){ return !s.empty(); }) | publish() | ref_count(); // filter to last string in each lineauto closes = strings | filter( [](const string& s){ return s.back() == '\r'; }) | Rx::map([](const string&){return0;}); // group strings by lineauto linewindows = strings | window_toggle(closes | start_with(0), [=](int){return closes;}); // reduce the strings for a line into one stringauto lines = linewindows | flat_map([&](observable<string> w) { return w | start_with<string>("") | sum() | Rx::map(removespaces); }); // print result lines | subscribe<string>(println(cout)); return0; }The ReactiveX Observable model allows you to treat streams of asynchronous events with the same sort of simple, composable operations that you use for collections of data items like arrays. It frees you from tangled webs of callbacks, and thereby makes your code more readable and less prone to bugs.
Credit
Other language implementations
Java:
JavaScript:
C#:
Resources
Cloning RxCpp
RxCpp uses a git submodule (in ext/catch) for the excellent
library. The easiest way to ensure that the submodules are included in the clone is to add --recursive in the clone command.
git clone --recursive https://github.com/ReactiveX/RxCpp.git cd RxCppInstalling
To install RxCpp into your OS you need to follow standart procedure:
mkdir build cd build cmake .. make install If you're using the vcpkg dependency manager, you can install RxCpp using a single one-line command:
vcpkg install rxcpp Vcpkg will acquire RxCpp, build it from source in your computer, and provide CMake integration support for your projects.
See the
for more information.
Importing
After you have successfully installed RxCpp you can import it into any project by simply adding to your CMakeLists.txt:
find_package(rxcppCONFIG)Building RxCpp Unit Tests
RxCpp is regularly tested on OSX and Windows.
RxCpp is regularly built with Clang, Gcc and VC
RxCpp depends on the latest compiler releases.
RxCpp uses CMake to create build files for several platforms and IDE's
ide builds
XCode
mkdir projects/build cd projects/build cmake -G"Xcode" -DRXCPP_DISABLE_TESTS_AND_EXAMPLES=0 ../CMake -B.Visual Studio 2017
mkdir projects\build cd projects\build cmake -G "Visual Studio 15" -DRXCPP_DISABLE_TESTS_AND_EXAMPLES=0 ..\CMake\ msbuild Project.slnmakefile builds
OSX
mkdir projects/build cd projects/build cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DRXCPP_DISABLE_TESTS_AND_EXAMPLES=0 -B. ../CMake makeLinux --- Clang
mkdir projects/build cd projects/build cmake -G"Unix Makefiles" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXE_LINKER_FLAGS="-stdlib=libc++" -DRXCPP_DISABLE_TESTS_AND_EXAMPLES=0 -B. ../CMake makeLinux --- GCC
mkdir projects/build cd projects/build cmake -G"Unix Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DRXCPP_DISABLE_TESTS_AND_EXAMPLES=0 -B. ../CMake makeWindows
mkdir projects\build cd projects\build cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DRXCPP_DISABLE_TESTS_AND_EXAMPLES=0 -B. ..\CMake nmakeThe build only produces test and example binaries.
Running tests
You can use the CMake test runner ctest
You can run the test binaries directly rxcpp_test_*
Tests can be selected by name or tag Example of by-tag
rxcpp_test_subscription [perf]
Documentation
RxCpp uses Doxygen to generate project
.
When Doxygen+Graphviz is installed, CMake creates a special build task named doc. It creates actual documentation and puts it to projects/doxygen/html/ folder, which can be published to the gh-pages branch. Each merged pull request will build the docs and publish them.
Contributing Code
Before submitting a feature or substantial code contribution please discuss it with the team and ensure it follows the product roadmap. Note that all code submissions will be rigorously reviewed and tested by the Rx Team, and only those that meet an extremely high bar for both quality and design/roadmap appropriateness will be merged into the source.
Microsoft Open Source Code of Conduct
This project has adopted the
Microsoft Open Source Code of Conduct
. For more information see the
or contact
with any additional questions or comments.