Filtering operators are operators that emit only part of items that satisfies some condition.
More...
Filtering operators are operators that emit only part of items that satisfies some condition.
See also https://reactivex.io/documentation/operators.html#filtering
◆ distinct()
auto rpp::operators::distinct
(
)
inline
For each item from this observable, filter out repeated values and emit only items that have not already been emitted.
Warning This operator keeps an std::unordered_set<T>
of past values, so std::hash<T> specialization is required.
See also https://reactivex.io/documentation/operators/distinct.html
◆ distinct_until_changed()
auto rpp::operators::distinct_until_changed
(
EqualityFn && equality_fn )
◆ element_at()
auto rpp::operators::element_at
(
size_t index )
inline
◆ filter()
auto rpp::operators::filter
(
Fn && predicate )
Emit only those items from an Observable that satisfies a provided predicate.
Actually this operator just checks if predicate returns true, then forwards emission
Performance notes:
No any heap allocations at all
No any copies/moves of emissions, just passing by const& to predicate and then forwarding
Parameters
predicate is predicate used to check emitted items. true -> items satisfies condition, false -> not
Note #include <rpp/operators/filter.hpp >
Example:
See also https://reactivex.io/documentation/operators/filter.html
Examples filter.cpp , and window_toggle.cpp .
◆ first()
auto rpp::operators::first
(
)
inline
Emit only the first item.
Actually this operator is take(1)
with exception during on_completed
if no any emision happens. So, it just forwards first obtained emission and emits on_completed immediately
Exceptions
Performance notes:
No any heap allocations
No any copies/moves just forwarding of emission
Note #include <rpp/operators/first.hpp >
Example:
[](const auto & v) { std::cout << "-" << v; },
[](const std::exception_ptr&) {},
[]() { std::cout << "-|" << std::endl; });
[](const auto & v) { std::cout << "-" << v; },
[](const std::exception_ptr&) { std::cout << "-x" << std::endl; },
[]() { std::cout << "-|" << std::endl; });
See also https://reactivex.io/documentation/operators/first.html
Examples first.cpp .
◆ last()
auto rpp::operators::last
(
)
inline
Emit only the last item provided before on_completed.
Actually this operator just updates std::optional
on every new emission and emits this value on_completed
Exceptions
Performance notes:
No any heap allocations
No replace std::optional with each new emission and move value from optional on_completed
Note #include <rpp/operators/last.hpp >
Example:
[](const auto & v) { std::cout << "-" << v; },
[](const std::exception_ptr&) {},
[]() { std::cout << "-|" << std::endl; });
[](const auto & v) { std::cout << "-" << v; },
[](const std::exception_ptr&) { std::cout << "-x" ; },
[]() { std::cout << "-|" << std::endl; });
See also https://reactivex.io/documentation/operators/last.html
Examples last.cpp .
◆ skip()
auto rpp::operators::skip
(
size_t count )
inline
Skip first count
items provided by observable then send rest items as expected.
Actually this operator just decrements counter and starts to forward emissions when counter reaches zero.
Performance notes:
No any heap allocations
No any copies/moves just forwarding of emission
Just simple size_t
decrementing
Parameters
count amount of items to be skipped
Note #include <rpp/operators/skip.hpp >
Example:
See also https://reactivex.io/documentation/operators/skip.html
Examples skip.cpp .
◆ take()
auto rpp::operators::take
(
size_t count )
inline
Emit only first count
items provided by observable, then send on_completed
Actually this operator just emits emissions while counter is not zero and decrements counter on each emission
Performance notes:
No any heap allocations
No any copies/moves just forwarding of emission
Just simple size_t
decrementing
Parameters
count amount of items to be emitted. 0 - instant complete
Note #include <rpp/operators/take.hpp >
Example:
See also https://reactivex.io/documentation/operators/take.html
Examples repeat.cpp , and retry.cpp .
◆ take_last()
auto rpp::operators::take_last
(
size_t count )
inline
◆ throttle()
auto rpp::operators::throttle
(
rpp::schedulers::duration period )
Emit emission from an Observable and then ignore subsequent values during duration
of time.
Actually this operator just keeps time of last emission, skips values until duration has passed, then forwards value, updates timepoint and etc...
Performance notes:
No any heap allocations at all
No any copies/moves of emissions, just passing by const& to predicate and then forwarding
Obtaining "now" every emission
Parameters
period is period of time to skip subsequent emissions
Template Parameters
Scheduler is type used to determine now()
. Shouldn't be used in production code
Note #include <rpp/operators/throttle.hpp >
Example: auto start = rpp::schedulers::clock_type::now();
})
std::cout << "> Sent value " << v << " at " << std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start).count() << std::endl;
return true ;
})
|
rpp::operators::subscribe ([&](
int v) { std::cout <<
">>> new value " << v <<
" at " << std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start).count() << std::endl; },
[](const std::exception_ptr&) {},
[&]() { std::cout << ">>> completed at " << std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start).count() << std::endl; });
See also https://reactivex.io/documentation/operators/debounce.html