summaryrefslogtreecommitdiff
path: root/Rx/v2/examples/doxygen/range.cpp
diff options
context:
space:
mode:
authorKirk Shoop <kirk.shoop@microsoft.com>2015-04-24 16:44:05 -0700
committerKirk Shoop <kirk.shoop@microsoft.com>2015-04-24 16:44:05 -0700
commitb1dd5d5c18553a9f1704a8d7ae64bca5f3b85d10 (patch)
tree047563dffef47c5d5bac11fc17d7a2cd9820ae08 /Rx/v2/examples/doxygen/range.cpp
parent9b2e07af319fefa1053f327ee07add4cf58dde19 (diff)
downloadRxCpp-b1dd5d5c18553a9f1704a8d7ae64bca5f3b85d10.tar.gz
adding docs in order to update readme.html code
Diffstat (limited to 'Rx/v2/examples/doxygen/range.cpp')
-rw-r--r--Rx/v2/examples/doxygen/range.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/Rx/v2/examples/doxygen/range.cpp b/Rx/v2/examples/doxygen/range.cpp
new file mode 100644
index 0000000..af66359
--- /dev/null
+++ b/Rx/v2/examples/doxygen/range.cpp
@@ -0,0 +1,112 @@
+#include "rxcpp/rx.hpp"
+
+#include "rxcpp/rx-test.hpp"
+#include "catch.hpp"
+
+SCENARIO("range sample"){
+ printf("//! [range sample]\n");
+ auto values1 = rxcpp::observable<>::range(1, 5);
+ values1.
+ subscribe(
+ [](int v){printf("OnNext: %d\n", v);},
+ [](){printf("OnCompleted\n");});
+ printf("//! [range sample]\n");
+}
+
+SCENARIO("range concat sample"){
+ printf("//! [range concat sample]\n");
+
+ auto values = rxcpp::observable<>::range(1); // infinite (until overflow) stream of integers
+
+ auto s1 = values.
+ take(3).
+ map([](int prime) { return std::make_tuple("1:", prime);});
+
+ auto s2 = values.
+ take(3).
+ map([](int prime) { return std::make_tuple("2:", prime);});
+
+ s1.
+ concat(s2).
+ subscribe(rxcpp::util::apply_to(
+ [](const char* s, int p) {
+ printf("%s %d\n", s, p);
+ }));
+ printf("//! [range concat sample]\n");
+}
+
+SCENARIO("range merge sample"){
+ printf("//! [range merge sample]\n");
+
+ auto values = rxcpp::observable<>::range(1); // infinite (until overflow) stream of integers
+
+ auto s1 = values.
+ map([](int prime) { return std::make_tuple("1:", prime);});
+
+ auto s2 = values.
+ map([](int prime) { return std::make_tuple("2:", prime);});
+
+ s1.
+ merge(s2).
+ take(6).
+ as_blocking().
+ subscribe(rxcpp::util::apply_to(
+ [](const char* s, int p) {
+ printf("%s %d\n", s, p);
+ }));
+ printf("//! [range merge sample]\n");
+}
+
+SCENARIO("threaded range concat sample"){
+ printf("//! [threaded range concat sample]\n");
+ auto threads = rxcpp::observe_on_event_loop();
+
+ auto values = rxcpp::observable<>::range(1); // infinite (until overflow) stream of integers
+
+ auto s1 = values.
+ subscribe_on(threads).
+ take(3).
+ map([](int prime) { std::this_thread::yield(); return std::make_tuple("1:", prime);});
+
+ auto s2 = values.
+ subscribe_on(threads).
+ take(3).
+ map([](int prime) { std::this_thread::yield(); return std::make_tuple("2:", prime);});
+
+ s1.
+ concat(s2).
+ observe_on(threads).
+ as_blocking().
+ subscribe(rxcpp::util::apply_to(
+ [](const char* s, int p) {
+ printf("%s %d\n", s, p);
+ }));
+ printf("//! [threaded range concat sample]\n");
+}
+
+SCENARIO("threaded range merge sample"){
+ printf("//! [threaded range merge sample]\n");
+ auto threads = rxcpp::observe_on_event_loop();
+
+ auto values = rxcpp::observable<>::range(1); // infinite (until overflow) stream of integers
+
+ auto s1 = values.
+ subscribe_on(threads).
+ map([](int prime) { std::this_thread::yield(); return std::make_tuple("1:", prime);});
+
+ auto s2 = values.
+ subscribe_on(threads).
+ map([](int prime) { std::this_thread::yield(); return std::make_tuple("2:", prime);});
+
+ s1.
+ merge(s2).
+ take(6).
+ observe_on(threads).
+ as_blocking().
+ subscribe(rxcpp::util::apply_to(
+ [](const char* s, int p) {
+ printf("%s %d\n", s, p);
+ }));
+ printf("//! [threaded range merge sample]\n");
+}
+