summaryrefslogtreecommitdiff
path: root/Rx/v2/examples
diff options
context:
space:
mode:
authorGrigoriy Chudnov <g.chudnov@gmail.com>2016-07-17 11:07:40 +0300
committerGrigoriy Chudnov <g.chudnov@gmail.com>2016-07-17 11:07:40 +0300
commit1d1f23fec52a411ecbd631587544f7453a9ec87b (patch)
tree39272e8f849a08d720e5b438925b2f850431bfc4 /Rx/v2/examples
parent4c80b04fc1774b5ea581df103895800ed3a78df6 (diff)
downloadRxCpp-1d1f23fec52a411ecbd631587544f7453a9ec87b.tar.gz
add switch_if_empty, default_if_empty
Diffstat (limited to 'Rx/v2/examples')
-rw-r--r--Rx/v2/examples/doxygen/default_if_empty.cpp17
-rw-r--r--Rx/v2/examples/doxygen/switch_if_empty.cpp33
2 files changed, 50 insertions, 0 deletions
diff --git a/Rx/v2/examples/doxygen/default_if_empty.cpp b/Rx/v2/examples/doxygen/default_if_empty.cpp
new file mode 100644
index 0000000..9ac8e64
--- /dev/null
+++ b/Rx/v2/examples/doxygen/default_if_empty.cpp
@@ -0,0 +1,17 @@
+#include "rxcpp/rx.hpp"
+
+#include "rxcpp/rx-test.hpp"
+#include "catch.hpp"
+
+SCENARIO("default_if_empty sample"){
+ printf("//! [default_if_empty sample]\n");
+
+ auto values = rxcpp::observable<>::empty<int>()
+ .default_if_empty(42);
+
+ values.subscribe(
+ [](int v) { printf("OnNext: %d\n", v); },
+ []() { printf("OnCompleted\n"); } );
+
+ printf("//! [default_if_empty sample]\n");
+}
diff --git a/Rx/v2/examples/doxygen/switch_if_empty.cpp b/Rx/v2/examples/doxygen/switch_if_empty.cpp
new file mode 100644
index 0000000..51faad7
--- /dev/null
+++ b/Rx/v2/examples/doxygen/switch_if_empty.cpp
@@ -0,0 +1,33 @@
+#include "rxcpp/rx.hpp"
+
+#include "rxcpp/rx-test.hpp"
+#include "catch.hpp"
+
+SCENARIO("switch_if_empty sample"){
+ printf("//! [switch_if_empty sample]\n");
+
+ auto values = rxcpp::observable<>::empty<int>()
+ .switch_if_empty(rxcpp::observable<>::range(1, 5));
+
+ values.subscribe(
+ [](int v) { printf("OnNext: %d\n", v); },
+ []() { printf("OnCompleted\n"); } );
+
+ printf("//! [switch_if_empty sample]\n");
+}
+
+SCENARIO("switch_if_empty - operator syntax sample") {
+ using namespace rxcpp;
+ using namespace rxcpp::sources;
+ using namespace rxcpp::operators;
+
+ printf("//! [switch_if_empty - operator syntax sample]\n");
+ auto values = empty<int>()
+ | switch_if_empty(range(1, 5));
+
+ values.subscribe(
+ [](int v) { printf("OnNext: %d\n", v); },
+ []() { printf("OnCompleted\n"); } );
+
+ printf("//! [switch_if_empty - operator syntax sample]\n");
+}