ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
Aggregate Operators

Aggregate operators are operators that operate on the entire sequence of items emitted by an Observable. More...

Functions

template<typename Seed , typename Accumulator >
requires (!utils::is_not_template_callable<Accumulator> || std::same_as<std::decay_t<Seed>, std::invoke_result_t<Accumulator, std::decay_t<Seed> &&, rpp::utils::convertible_to_any>>)
auto rpp::operators::reduce (Seed &&seed, Accumulator &&accumulator)
 Apply a function to each item emitted by an Observable, sequentially, and emit the final value.
 
template<typename Accumulator >
auto rpp::operators::reduce (Accumulator &&accumulator)
 Apply a function to each item emitted by an Observable, sequentially, and emit the final value.
 

Detailed Description

Aggregate operators are operators that operate on the entire sequence of items emitted by an Observable.

See also
https://reactivex.io/documentation/operators.html#mathematical

Function Documentation

◆ reduce() [1/2]

template<typename Accumulator >
auto rpp::operators::reduce ( Accumulator && accumulator)

Apply a function to each item emitted by an Observable, sequentially, and emit the final value.

There is no initial value for seed, so, first value would be used as seed value and forwarded as is.

Parameters
accumulatorfunction which accepts seed value and new value from observable and return new value of seed. Can accept seed by move-reference.
Note
#include <rpp/operators/reduce.hpp>
Example
| rpp::operators::reduce(std::plus<int>{})
| rpp::operators::subscribe([](int v) { std::cout << v << std::endl; });
// Output: 6
See also
https://reactivex.io/documentation/operators/reduce.html

◆ reduce() [2/2]

template<typename Seed , typename Accumulator >
requires (!utils::is_not_template_callable<Accumulator> || std::same_as<std::decay_t<Seed>, std::invoke_result_t<Accumulator, std::decay_t<Seed> &&, rpp::utils::convertible_to_any>>)
auto rpp::operators::reduce ( Seed && seed,
Accumulator && accumulator )

Apply a function to each item emitted by an Observable, sequentially, and emit the final value.

Parameters
seedinitial value for seed
accumulatorfunction which accepts seed value and new value from observable and return new value of seed. Can accept seed by move-reference.
Note
#include <rpp/operators/reduce.hpp>
Example
| rpp::operators::reduce(std::string{}, [](std::string&& seed, int v) { return std::move(seed) + std::to_string(v) + ","; })
| rpp::operators::subscribe([](const std::string& v) { std::cout << v << std::endl; });
// Output: 1,2,3,
See also
https://reactivex.io/documentation/operators/reduce.html
Examples
reduce.cpp.