RxCpp
The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
Classes | Namespaces | Macros | Functions
rx-group_by.hpp File Reference

Return an observable that emits grouped_observables, each of which corresponds to a unique key value and each of which emits those items from the source observable that share that key value. More...

#include "../rx-includes.hpp"
Include dependency graph for rx-group_by.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rxcpp::member_overload< group_by_tag >
 

Namespaces

 rxcpp
 
 rxcpp::operators
 

Macros

#define RXCPP_OPERATORS_RX_GROUP_BY_HPP
 

Functions

template<class... AN>
auto rxcpp::operators::group_by (AN &&...an) -> operator_factory< group_by_tag, AN... >
 Return an observable that emits grouped_observables, each of which corresponds to a unique key value and each of which emits those items from the source observable that share that key value. More...
 

Detailed Description

Return an observable that emits grouped_observables, each of which corresponds to a unique key value and each of which emits those items from the source observable that share that key value.

Template Parameters
KeySelectorthe type of the key extracting function
MarbleSelectorthe type of the element extracting function
BinaryPredicatethe type of the key comparing function
Parameters
ksa function that extracts the key for each item (optional)
msa function that extracts the return element for each item (optional)
pa function that implements comparison of two keys (optional)
Returns
Observable that emits values of grouped_observable type, each of which corresponds to a unique key value and each of which emits those items from the source observable that share that key value.
Sample Code
bool less(int v1, int v2){
return v1 < v2;
}
auto data = rxcpp::observable<>::range(0, 8).
map([](int v){
std::stringstream s;
s << "Value " << v;
return std::make_pair(v % 3, s.str());
});
auto values = data.group_by(
[](std::pair<int, std::string> v){return v.first;},
[](std::pair<int, std::string> v){return v.second;},
less);
values.
auto key = g.get_key();
printf("OnNext: key = %d\n", key);
[key](const std::string& v){printf("[key %d] OnNext: %s\n", key, v.c_str());},
[key](){printf("[key %d] OnCompleted\n", key);});
},
[](){printf("OnCompleted\n");});
OnNext: key = 0
[key 0] OnNext: Value 0
OnNext: key = 1
[key 1] OnNext: Value 1
OnNext: key = 2
[key 2] OnNext: Value 2
[key 0] OnNext: Value 3
[key 1] OnNext: Value 4
[key 2] OnNext: Value 5
[key 0] OnNext: Value 6
[key 1] OnNext: Value 7
[key 2] OnNext: Value 8
[key 0] OnCompleted
[key 1] OnCompleted
[key 2] OnCompleted
OnCompleted
Sample Code
auto values = rxcpp::observable<>::range(0, 8).
[](int v){return v % 3;},
[](int v){return 10 * v;});
values.
auto key = g.get_key();
printf("OnNext: key = %d\n", key);
[key](int v){printf("[key %d] OnNext: %d\n", key, v);},
[key](){printf("[key %d] OnCompleted\n", key);});
},
[](){printf("OnCompleted\n");});
OnNext: key = 0
[key 0] OnNext: 0
OnNext: key = 1
[key 1] OnNext: 10
OnNext: key = 2
[key 2] OnNext: 20
[key 0] OnNext: 30
[key 1] OnNext: 40
[key 2] OnNext: 50
[key 0] OnNext: 60
[key 1] OnNext: 70
[key 2] OnNext: 80
[key 0] OnCompleted
[key 1] OnCompleted
[key 2] OnCompleted
OnCompleted

Macro Definition Documentation

#define RXCPP_OPERATORS_RX_GROUP_BY_HPP