ReactivePlusPlus
ReactiveX implementation for C++20
|
Operators modify observables and extend them with custom logic. More...
Topics | |
Transforming Operators | |
Transforming operators are operators that transform items provided by observable. | |
Filtering Operators | |
Filtering operators are operators that emit only part of items that satisfies some condition. | |
Conditional Operators | |
Conditional operators are operators that emit items based on some condition including condition of items from other observables. | |
Combining Operators | |
Combining operators are operators that combines emissions of multiple observables into same observable by some rule. | |
Utility Operators | |
Utility operators are operators that provide some extra functionality without changing of original values, but changing of behaviour. | |
Connectable Operators | |
Connectable operators are operators that provide extra functionality for multicasting of controlling of subscription. | |
Aggregate Operators | |
Aggregate operators are operators that operate on the entire sequence of items emitted by an Observable. | |
Error Handling Operators | |
Operators that help to recover from error notifications from an Observable. | |
Creational Operators | |
Creational operators are operators that create new observable. | |
Concepts | |
concept | rpp::constraint::operator_subscribe |
Simple operator defining logic how to subscribe passed observer to passed observable. In most cases it means operator have some custom logic over observable too, so, you need to have access to observable, for example, subscribe to observable multiple times. | |
concept | rpp::constraint::operator_lift |
Accept downstream observer and return new upstream (of type Type) observer. | |
concept | rpp::constraint::operator_lift_with_disposables_strategy |
Same as rpp::constraint::operator_lift but with custom disposables logic. For example, if you are manually create storage for disposables and want to do it optimal. | |
concept | rpp::constraint::operator_ |
Operators modify observables and extend them with custom logic.
Observables emit values based on underlying logic, such as iterating over a vector and etc. Operators allow you to enhance this stream, for example, by filtering values, transforming them, etc., resulting in a more suitable stream for specific cases.
Example: Create an observable to read characters from console input, continue until '0' is encountered, filter out non-letter characters, and send the remaining letters as uppercase to the observer:
This example creates an observable of int
using the create
operator, which emits the value 1
and then completes. The type of this observable is rpp::observable<int, ...>
, where ...
is an implementation-defined type. To convert int
to std::string
, you can use the map
operator:
Now it is an observable of strings
(rpp::observable<std::string, ...>
). The map
operator is a functor-adaptor that accepts an observable and returns another observable. It transforms the original observable's type to the "final type" by invoking the passed function. In this case, the final type is std::string
. The map
operator can be implemented in multiple ways:
1) call-based (function/functor or others) - operator accepts (old) observable and returns new (modified) observable
It is template for such an functor-adaptor. It is also fully valid example of call-based operator:
This converts the observable to a concatenation of the original observable and just(2)
.
2) type-traits based - should satisfy rpp::constraint::operator_ concept.
For example, you can implement such an operator like this:
But in this case you are missing disposables-related functionality. So, it is better to implement it via providing custom observer's strategy with correct handling of disposables. Check real rpp::operators::map implementation for it =)