summaryrefslogtreecommitdiff
path: root/Rx/v2/examples/doxygen/switch_if_empty.cpp
blob: 51faad7a900bb23c080d3db51989be10e7b284ad (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
#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");
}