ReactivePlusPlus
ReactiveX implementation for C++20
Toggle main menu visibility
Loading...
Searching...
No Matches
window_toggle.cpp
#include <rpp/rpp.hpp>
#include <iostream>
int
main()
{
size_t
counter{};
auto
source =
rpp::source::just
(
rpp::schedulers::current_thread
{}, 1, 2, 3, 4, 5) |
rpp::operators::publish
() |
rpp::operators::ref_count
();
source
|
rpp::operators::window_toggle
(source, [source](
int
) {
return
source |
rpp::ops::filter
([](
int
v) {
return
v % 2 == 0; }); })
|
rpp::operators::subscribe
([&counter](
const
rpp::window_toggle_observable<int>& obs) {
std::cout <<
"New observable "
<< ++counter << std::endl;
obs.subscribe([counter](
int
v) { std::cout << counter <<
": "
<< v <<
" "
<< std::endl; }, [counter]() { std::cout <<
"closing "
<< counter << std::endl; });
});
// Output:
// New observable 1
// 1: 1
// New observable 2
// 1: 2
// 2: 2
// closing 1
// New observable 3
// 2: 3
// 3: 3
// New observable 4
// 2: 4
// 3: 4
// 4: 4
// closing 2
// closing 3
// New observable 5
// 4: 5
// 5: 5
// closing 4
// closing 5
return
0;
}
rpp::schedulers::current_thread
Schedules execution of schedulables via queueing tasks to the caller thread with priority to time_poi...
Definition
current_thread.hpp:86
rpp::operators::publish
auto publish()
Converts ordinary observable to rpp::connectable_observable with help of inline instsantiated publish...
Definition
publish.hpp:22
rpp::operators::ref_count
auto ref_count()
Forces rpp::connectable_observable to behave like common observable.
Definition
ref_count.hpp:29
rpp::source::just
auto just(const TScheduler &scheduler, T &&item, Ts &&... items)
Creates rpp::observable that emits a particular items and completes.
Definition
from.hpp:201
rpp::operators::filter
auto filter(Fn &&predicate)
Emit only those items from an Observable that satisfies a provided predicate.
Definition
filter.hpp:91
rpp::operators::window_toggle
auto window_toggle(TOpeningsObservable &&openings, TClosingsSelectorFn &&closings_selector)
Subdivide original observable into sub-observables (window observables) and emit sub-observables of i...
Definition
window_toggle.hpp:236
rpp::operators::subscribe
auto subscribe(observer< Type, ObserverStrategy > &&observer)
Subscribes passed observer to emissions from this observable.
Definition
subscribe.hpp:226
Generated by
1.17.0