ReactivePlusPlus
ReactiveX implementation for C++20
Toggle main menu visibility
Loading...
Searching...
No Matches
first.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/AlexInLog/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
namespace
rpp::operators::details
19
{
20
template
<rpp::constra
int
::observer TObserver>
21
struct
first_observer_strategy
22
{
23
static
constexpr
auto
preferred_disposables_mode = rpp::details::observers::disposables_mode::None;
24
25
RPP_NO_UNIQUE_ADDRESS TObserver observer;
26
27
template
<
typename
T>
28
void
on_next(T&& v)
const
29
{
30
observer.on_next(std::forward<T>(v));
31
observer.on_completed();
32
}
33
34
void
on_completed()
const
35
{
36
observer.on_error(std::make_exception_ptr(
utils::not_enough_emissions
{
"first() operator expects at least one emission from observable before completion"
}));
37
}
38
39
void
on_error(
const
std::exception_ptr& err)
const
{ observer.on_error(err); }
40
41
void
set_upstream(
const
disposable_wrapper
& d) { observer.set_upstream(d); }
42
43
bool
is_disposed()
const
{
return
observer.is_disposed(); }
44
};
45
46
struct
first_t
: lift_operator<first_t>
47
{
48
using
lift_operator<
first_t
>::lift_operator;
49
50
template
<rpp::constra
int
::decayed_type T>
51
struct
operator_traits
52
{
53
using
result_type = T;
54
55
template
<rpp::constra
int
::observer_of_type<result_type> TObserver>
56
using
observer_strategy =
first_observer_strategy<TObserver>
;
57
};
58
59
template
<rpp::details::observables::constra
int
::disposables_strategy Prev>
60
using
updated_optimal_disposables_strategy = Prev;
61
};
62
}
// namespace rpp::operators::details
63
64
namespace
rpp::operators
65
{
87
*
88
* @ingroup filtering_operators
89
* @see https://reactivex.io/documentation/operators/first.html
90
*/
91
inline
auto
first
()
92
{
93
return
details::first_t
{};
94
}
95
}
// namespace rpp::operators
rpp::disposable_wrapper
disposable_wrapper_impl< interface_disposable > disposable_wrapper
Wrapper to keep "simple" disposable. Specialization of rpp::disposable_wrapper_impl.
Definition
fwd.hpp:34
rpp::operators::first
auto first()
Emit only the first item.
Definition
first.hpp:87
rpp::operators::details::first_observer_strategy
Definition
first.hpp:22
rpp::operators::details::first_t::operator_traits
Definition
first.hpp:52
rpp::operators::details::first_t
Definition
first.hpp:47
rpp::utils::not_enough_emissions
Definition
exceptions.hpp:18
src
rpp
rpp
operators
first.hpp
Generated by
1.17.0