ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
skip.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2023 - present.
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// https://www.boost.org/LICENSE_1_0.txt)
7//
8// Project home: https://github.com/victimsnino/ReactivePlusPlus
9//
10
11#pragma once
12
13#include <rpp/operators/fwd.hpp>
14
15#include <rpp/defs.hpp>
16#include <rpp/operators/details/strategy.hpp>
17
18#include <cstddef>
19
20namespace rpp::operators::details
21{
22 template<rpp::constraint::observer TObserver>
24 {
25 static constexpr auto preferred_disposables_mode = rpp::details::observers::disposables_mode::None;
26
27 RPP_NO_UNIQUE_ADDRESS TObserver observer;
28 mutable size_t count{};
29
30 template<typename T>
31 void on_next(T&& v) const
32 {
33 if (count == 0)
34 observer.on_next(std::forward<T>(v));
35 else
36 --count;
37 }
38
39 void on_error(const std::exception_ptr& err) const { observer.on_error(err); }
40
41 void on_completed() const { observer.on_completed(); }
42
43 void set_upstream(const disposable_wrapper& d) { observer.set_upstream(d); }
44
45 bool is_disposed() const { return observer.is_disposed(); }
46 };
47
48 struct skip_t : lift_operator<skip_t, size_t>
49 {
50 using lift_operator<skip_t, size_t>::lift_operator;
51
52 template<rpp::constraint::decayed_type T>
54 {
55 using result_type = T;
56
57 template<rpp::constraint::observer_of_type<result_type> TObserver>
59 };
60
61 template<rpp::details::observables::constraint::disposables_strategy Prev>
62 using updated_optimal_disposables_strategy = Prev;
63 };
64} // namespace rpp::operators::details
65
66namespace rpp::operators
67{
93 inline auto skip(size_t count)
94 {
95 return details::skip_t{count};
96 }
97} // namespace rpp::operators
void on_next(const Type &v) const noexcept
Observable calls this method to notify observer about new value.
Definition observer.hpp:84
void set_upstream(const disposable_wrapper &d) noexcept
Observable calls this method to pass disposable. Observer disposes this disposable WHEN observer want...
Definition observer.hpp:49
void on_completed() const noexcept
Observable calls this method to notify observer about completion of emissions.
Definition observer.hpp:135
void on_error(const std::exception_ptr &err) const noexcept
Observable calls this method to notify observer about some error during generation next data.
Definition observer.hpp:120
bool is_disposed() const noexcept
Observable calls this method to check if observer interested or not in emissions.
Definition observer.hpp:74
Base class for any observer used in RPP. It handles core callbacks of observers. Objects of this clas...
Definition observer.hpp:172
Definition strategy.hpp:28
auto skip(size_t count)
Skip first count items provided by observable then send rest items as expected.
Definition skip.hpp:89
Definition skip.hpp:49