Skip to Content
C++ Reactive Programming
book

C++ Reactive Programming

by Praseed Pai, Peter Abraham
June 2018
Intermediate to advanced
348 pages
8h 45m
English
Packt Publishing
Content preview from C++ Reactive Programming

Writing a custom transformation operator

Let's write a simple program to implement a custom operator by combining other operators, where we filter stream of numbers for odd numbers, transform numbers into its square, and take only first three elements from the stream:

//------ CustomOperator1.cpp #include "rxcpp/rx.hpp" namespace rx { using namespace rxcpp; using namespace rxcpp::operators; using namespace rxcpp::sources; using namespace rxcpp::util; } //------ operator to filter odd number, find square & take first three items std::function<rx::observable<int>(rx::observable<int>)> getOddNumSquare() { return [](rx::observable<int> item) { return item. filter([](int v){ return v%2; }). map([](const int v) { return v*v; }). take(3). //------ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Functional Programming in C++

Functional Programming in C++

Ivan Cukic

Publisher Resources

ISBN: 9781788629775Supplemental Content