diff options
author | Kirk Shoop <kirk.shoop@microsoft.com> | 2015-03-24 09:51:54 -0700 |
---|---|---|
committer | Kirk Shoop <kirk.shoop@microsoft.com> | 2015-03-24 09:51:54 -0700 |
commit | bd97cedb5a11c0666c14efa9d5abb9769480a884 (patch) | |
tree | 5bb827a70abc3cb457954e2e16977fce849289a2 /Rx/v2/examples/cep/main.cpp | |
parent | 0f89328f0b1ce4b1649759d56641593f6877a0a6 (diff) | |
download | RxCpp-bd97cedb5a11c0666c14efa9d5abb9769480a884.tar.gz |
add cep sample
answers #105
Diffstat (limited to 'Rx/v2/examples/cep/main.cpp')
-rw-r--r-- | Rx/v2/examples/cep/main.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Rx/v2/examples/cep/main.cpp b/Rx/v2/examples/cep/main.cpp new file mode 100644 index 0000000..587595f --- /dev/null +++ b/Rx/v2/examples/cep/main.cpp @@ -0,0 +1,43 @@ + +#include "rxcpp/rx.hpp" +// create alias' to simplify code +// these are owned by the user so that +// conflicts can be managed by the user. +namespace rx=rxcpp; +namespace rxsub=rxcpp::subjects; +namespace rxu=rxcpp::util; + +#include <cctype> +#include <clocale> + +// At this time, RxCpp will fail to compile if the contents +// of the std namespace are merged into the global namespace +// DO NOT USE: 'using namespace std;' + +int main() +{ + auto keys = rx::observable<>::create<int>( + [](rx::subscriber<int> dest){ + for (;;) { + int key = std::cin.get(); + dest.on_next(key); + } + }). + publish(); + + auto a = keys. + filter([](int key){return std::tolower(key) == 'a';}); + + auto g = keys. + filter([](int key){return std::tolower(key) == 'g';}); + + a.merge(g). + subscribe([](int key){ + std::cout << key << std::endl; + }); + + // run the loop in create + keys.connect(); + + return 0; +} |