ReactivePlusPlus
ReactiveX implementation for C++20
Toggle main menu visibility
Loading...
Searching...
No Matches
flat_map.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/defs.hpp>
14
#include <rpp/operators/map.hpp>
15
#include <rpp/operators/merge.hpp>
16
17
namespace
rpp::operators::details
18
{
19
template
<rpp::constra
int
::decayed_type Fn>
20
struct
flat_map_t
21
{
22
RPP_NO_UNIQUE_ADDRESS Fn m_fn;
23
24
template
<rpp::constra
int
::observable TObservable>
25
auto
operator()(TObservable&&
observable
)
const
&
26
{
27
static_assert
(std::invocable<Fn, rpp::utils::extract_observable_type_t<TObservable>> &&
rpp::constraint::observable<std::invoke_result_t<Fn, rpp::utils::extract_observable_type_t<TObservable>
>>,
"fn should return observable"
);
28
return
std::forward<TObservable>(
observable
)
29
|
rpp::ops::map
(m_fn)
30
|
rpp::ops::merge
();
31
}
32
33
template
<rpp::constra
int
::observable TObservable>
34
auto
operator()(TObservable&&
observable
) &&
35
{
36
static_assert
(std::invocable<Fn, rpp::utils::extract_observable_type_t<TObservable>> &&
rpp::constraint::observable<std::invoke_result_t<Fn, rpp::utils::extract_observable_type_t<TObservable>
>>,
"fn should return observable"
);
37
return
std::forward<TObservable>(
observable
)
38
|
rpp::ops::map
(std::move(m_fn))
39
|
rpp::ops::merge
();
40
}
41
};
42
43
}
// namespace rpp::operators::details
44
45
namespace
rpp::operators
46
{
47
64
* @see https://reactivex.io/documentation/operators/flatmap.html
65
*/
66
template
<
typename
Fn>
67
requires
(!
utils::is_not_template_callable<Fn>
||
rpp::constraint::observable<std::invoke_result_t<Fn, rpp::utils::convertible_to_any>
>)
68
auto
flat_map
(Fn&& callable)
69
{
70
return
details::flat_map_t<std::decay_t<Fn>
>{std::forward<Fn>(callable)};
71
}
72
73
}
// namespace rpp::operators
rpp::observable
Base class for any observable used in RPP. It handles core callbacks of observable.
Definition
observable.hpp:38
rpp::constraint::observable
Definition
fwd.hpp:80
rpp::utils::is_not_template_callable
Definition
function_traits.hpp:45
rpp::operators::merge
auto merge()
Converts observable of observables of items into observable of items via merging emissions.
Definition
merge.hpp:221
rpp::operators::map
auto map(Fn &&callable)
Transforms the items emitted by an Observable via applying a function to each item and emitting resul...
Definition
map.hpp:94
rpp::operators::flat_map
auto flat_map(Fn &&callable)
Transform the items emitted by an Observable into Observables, then flatten the emissions from those ...
Definition
flat_map.hpp:64
rpp::operators::details::flat_map_t
Definition
flat_map.hpp:21
src
rpp
rpp
operators
flat_map.hpp
Generated by
1.17.0