blob: 587595f2b6cfdf29b509107dcbb17c1cb80ca2a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}
|