summaryrefslogtreecommitdiff
path: root/Rx/v2/src/rxcpp/sources/rx-iterate.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Rx/v2/src/rxcpp/sources/rx-iterate.hpp')
-rw-r--r--Rx/v2/src/rxcpp/sources/rx-iterate.hpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/Rx/v2/src/rxcpp/sources/rx-iterate.hpp b/Rx/v2/src/rxcpp/sources/rx-iterate.hpp
index be98c0c..8832775 100644
--- a/Rx/v2/src/rxcpp/sources/rx-iterate.hpp
+++ b/Rx/v2/src/rxcpp/sources/rx-iterate.hpp
@@ -7,6 +7,28 @@
#include "../rx-includes.hpp"
+/*! \file rx-iterate.hpp
+
+ \brief Returns an observable that sends each value in the collection, on the specified scheduler.
+
+ \tparam Collection the type of the collection of values that this observable emits
+ \tparam Coordination the type of the scheduler (optional)
+
+ \param c collection containing values to send
+ \param cn the scheduler to use for scheduling the items (optional)
+
+ \return Observable that sends each value in the collection.
+
+ \sample
+ \snippet iterate.cpp iterate sample
+ \snippet output.txt iterate sample
+
+ \sample
+ \snippet iterate.cpp threaded iterate sample
+ \snippet output.txt threaded iterate sample
+
+*/
+
namespace rxcpp {
namespace sources {
@@ -132,12 +154,16 @@ struct iterate : public source_base<rxu::value_type_t<iterate_traits<Collection>
}
+/*! @copydoc rx-iterate.hpp
+ */
template<class Collection>
auto iterate(Collection c)
-> observable<rxu::value_type_t<detail::iterate_traits<Collection>>, detail::iterate<Collection, identity_one_worker>> {
return observable<rxu::value_type_t<detail::iterate_traits<Collection>>, detail::iterate<Collection, identity_one_worker>>(
detail::iterate<Collection, identity_one_worker>(std::move(c), identity_immediate()));
}
+/*! @copydoc rx-iterate.hpp
+ */
template<class Collection, class Coordination>
auto iterate(Collection c, Coordination cn)
-> observable<rxu::value_type_t<detail::iterate_traits<Collection>>, detail::iterate<Collection, Coordination>> {
@@ -145,17 +171,52 @@ auto iterate(Collection c, Coordination cn)
detail::iterate<Collection, Coordination>(std::move(c), std::move(cn)));
}
+/*! Returns an observable that sends an empty set of values and then completes.
+
+ \tparam T the type of elements (not) to be sent
+
+ \return Observable that sends an empty set of values and then completes.
+
+ This is a degenerate case of rxcpp::observable<void,void>#from(Value0,ValueN...) operator.
+
+ \note This is a degenerate case of ```from(Value0 v0, ValueN... vn)``` operator.
+*/
template<class T>
auto from()
-> decltype(iterate(std::array<T, 0>(), identity_immediate())) {
return iterate(std::array<T, 0>(), identity_immediate());
}
+/*! Returns an observable that sends an empty set of values and then completes, on the specified scheduler.
+
+ \tparam T the type of elements (not) to be sent
+ \tparam Coordination the type of the scheduler
+
+ \return Observable that sends an empty set of values and then completes.
+
+ \note This is a degenerate case of ```from(Coordination cn, Value0 v0, ValueN... vn)``` operator.
+*/
template<class T, class Coordination>
auto from(Coordination cn)
-> typename std::enable_if<is_coordination<Coordination>::value,
decltype( iterate(std::array<T, 0>(), std::move(cn)))>::type {
return iterate(std::array<T, 0>(), std::move(cn));
}
+/*! Returns an observable that sends each value from its arguments list.
+
+ \tparam Value0 ...
+ \tparam ValueN the type of sending values
+
+ \param v0 ...
+ \param vn values to send
+
+ \return Observable that sends each value from its arguments list.
+
+ \sample
+ \snippet from.cpp from sample
+ \snippet output.txt from sample
+
+ \note This operator is useful to send separated values. If they are stored as a collection, use observable<void,void>::iterate instead.
+*/
template<class Value0, class... ValueN>
auto from(Value0 v0, ValueN... vn)
-> typename std::enable_if<!is_coordination<Value0>::value,
@@ -163,6 +224,24 @@ auto from(Value0 v0, ValueN... vn)
std::array<Value0, sizeof...(ValueN) + 1> c{{v0, vn...}};
return iterate(std::move(c), identity_immediate());
}
+/*! Returns an observable that sends each value from its arguments list, on the specified scheduler.
+
+ \tparam Coordination the type of the scheduler
+ \tparam Value0 ...
+ \tparam ValueN the type of sending values
+
+ \param cn the scheduler to use for scheduling the items
+ \param v0 ...
+ \param vn values to send
+
+ \return Observable that sends each value from its arguments list.
+
+ \sample
+ \snippet from.cpp threaded from sample
+ \snippet output.txt threaded from sample
+
+ \note This operator is useful to send separated values. If they are stored as a collection, use observable<void,void>::iterate instead.
+*/
template<class Coordination, class Value0, class... ValueN>
auto from(Coordination cn, Value0 v0, ValueN... vn)
-> typename std::enable_if<is_coordination<Coordination>::value,
@@ -171,6 +250,74 @@ auto from(Coordination cn, Value0 v0, ValueN... vn)
return iterate(std::move(c), std::move(cn));
}
+
+/*! Returns an observable that sends the specified item to observer and then completes.
+
+ \tparam T the type of the emitted item
+
+ \param v the value to send
+
+ \return Observable that sends the specified item to observer and then completes.
+
+ \sample
+ \snippet just.cpp just sample
+ \snippet output.txt just sample
+*/
+template<class Value0>
+auto just(Value0 v0)
+ -> typename std::enable_if<!is_coordination<Value0>::value,
+ decltype(iterate(*(std::array<Value0, 1>*)nullptr, identity_immediate()))>::type {
+ std::array<Value0, 1> c{{v0}};
+ return iterate(std::move(c), identity_immediate());
+}
+/*! Returns an observable that sends the specified item to observer and then completes, on the specified scheduler.
+
+ \tparam T the type of the emitted item
+ \tparam Coordination the type of the scheduler
+
+ \param v the value to send
+ \param cn the scheduler to use for scheduling the items
+
+ \return Observable that sends the specified item to observer and then completes.
+
+ \sample
+ \snippet just.cpp threaded just sample
+ \snippet output.txt threaded just sample
+*/
+template<class Value0, class Coordination>
+auto just(Value0 v0, Coordination cn)
+ -> typename std::enable_if<is_coordination<Coordination>::value,
+ decltype(iterate(*(std::array<Value0, 1>*)nullptr, std::move(cn)))>::type {
+ std::array<Value0, 1> c{{v0}};
+ return iterate(std::move(c), std::move(cn));
+}
+
+/*! Returns an observable that sends the specified values before it begins to send items emitted by the given observable.
+
+ \tparam Observable the type of the observable that emits values for resending
+ \tparam Value0 ...
+ \tparam ValueN the type of sending values
+
+ \param o the observable that emits values for resending
+ \param v0 ...
+ \param vn values to send
+
+ \return Observable that sends the specified values before it begins to send items emitted by the given observable.
+
+ \sample
+ \snippet start_with.cpp full start_with sample
+ \snippet output.txt full start_with sample
+
+ Instead of passing the observable as a parameter, you can use rxcpp::observable<T, SourceOperator>::start_with method of the existing observable:
+ \snippet start_with.cpp short start_with sample
+ \snippet output.txt short start_with sample
+*/
+template<class Observable, class Value0, class... ValueN>
+auto start_with(Observable o, Value0 v0, ValueN... vn)
+ -> decltype(from(rxu::value_type_t<Observable>(v0), rxu::value_type_t<Observable>(vn)...).concat(o)) {
+ return from(rxu::value_type_t<Observable>(v0), rxu::value_type_t<Observable>(vn)...).concat(o);
+}
+
}
}