Comments (12)
For C++, I'm personally a fan of operator >> with free functions, but it does involve the most compiler resource overhead and library writer overhead. E.g.:
std::vector<int> v;
v >> linq::select([](x) { return x * 2; });
I think a good template-file code generator could take the work out of generating all the linq operators. Free functions offer the most flexibility as far as Koenig lookup allows. I assume that's what you meant by operator<<?
from rxcpp.
When I did some testing the compiler was not able to deduce the type of the input parameter to select. The best I could produce come up with was:
v >> linq::select([](int x) { return x * 2; });
I don't have the code right here but I can provide it later if you want to see what I did.
from rxcpp.
C++ doesn't have a feature for detecting input arguments to a lambda. They have to be explicitly named. Also, due to shortsightedness in the design of the lambda feature, on most compilers you have to specifically say the type of the lambda argument too. E.g.:
v >> linq::select([](int x){ return x * 2; });
I've heard from multiple compiler designers that the compilers already could infer the type of the function argument, but speculate that no compiler implements it for fear of being incompatible with a future standard correcting the issue.
On the other hand, the boost::lambda library can infer argument types, but only for simple expressions -- it's really just an awesome hack:
v >> linq::select(_1 * 2);
from rxcpp.
I have both syntaxes working with the same code, in my experimental branch (https://rxcpp.codeplex.com/SourceControl/network/forks/kirkshoop/rxcpp?branch=static_observer_experiment)
Due to the fact that the operator >> pattern requires late binding of the source to the rx operator, the construction of each rx operator sends all its parameters through a couple more function calls and moves. Otherwise the code produced is the same.
Using operator >>
The repeated rxo:: namespace references are demotivating for me. But reopening the rxcpp::operators namespace makes it easier to promote the visibility of externally defined operators.
auto s = rx::observable<>::range(1, 100, 1)
>> rxo::filter(IsPrime)
>> rxo::subscribe([](int t) {
const auto prime = IsPrime(t) ? t : -1;
REQUIRE( t == prime );
});
Using member functions
I am going to start playing with ways to inject external operator functions to observable
auto s = rx::observable<>::range(1, 100, 1)
.filter(IsPrime)
.subscribe([](int t) {
const auto prime = IsPrime(t) ? t : -1;
REQUIRE( t == prime );
});
from rxcpp.
Excellent!
Regarding the rxo namespace: I think it looks fine. It's up to the user to do whatever works for him/her.
I would prefer range to be a free function rather than a static member function of observable. Especially if you take the operator >> route (which I think looks very promising!)
I like the rx namespace! Maybe a switch from rxcpp to rx would be in order? If you find yourself wondering if you are using c++ or not I guess you have bigger issues :)
Is it ok to open tickets with suggestions like the namespace name change?
from rxcpp.
Fixed a few build issues for clang but I wasn't able to send a pull request to your fork on CodePlex (wasn't able to fork your fork). It's here anyways: https://rxcpp.codeplex.com/SourceControl/network/forks/furuholm/rxcpp?branch=static_observer_experiment
from rxcpp.
Glad you like it.
Please do open tickets for suggestions like these.
Adding a range free function in the rxs namespace is easy. Feel free to add it.
My response to having rx as the real namespace is that it is too short. I do not want anyone to curse about how the rx class in their project conflicted with the namespace. I believe that namespaces are supposed to be unique. shortening them should be done with an alias in each project.
I can be persuaded that the namespace should omit the cpp redundancy. I am trying to make rxcpp the unique identifier in the larger Rx community, but in the project we could use namespace ReactiveExtensions. Sadly though it would make the compiler and debugger display of symbols even more noisy than it is. maybe a name somewhere between..
from rxcpp.
Sorry it took so long. I merged your changes for clang into my fork and pushed them.
I did modify the changes. My commit explains why.
Thanks!
from rxcpp.
@furuholm in order for your contributions to make it into the official repo you will need to have a CLA on file. You can do that here: http://cla.msopentech.com/
Thanks!
from rxcpp.
@kirkshoop will do!
from rxcpp.
The official repo has a v2 directory now.
v2 currently has support for
- '.'
- Allows Intellisense to work.
- slight perf improvement because the parameters do not have to be stored in a factory object until they are bound to a source by a binary operator
- has op() to lift external operators into the expression (could be renamed)
- '>>'
- shows direction of data
- subscribe and dispose do not flow in that direction
- '|'
- This is the operator used to combine boost range adapters
The binary operators have the following properties that are distinct from '.'
- Allows operators to be added by reopening the namespace
- Of course, the std namespace does not support identifiers being added - rx probably should do the same
- no Intellisense available
- requires much namespace repetition ala rxcpp::operators::
- Aliased to rxo:: is a bit better but still a lot of noise
- I do not recommend polluting the global namespace with identifiers like range, map, flat_map, filter, buffer, window, etc.. so 'using rxcpp::operators' is right out
from rxcpp.
v2 with support for all three syntax is in master
from rxcpp.
Related Issues (20)
- Flat map serializes output when using observable<>::create HOT 2
- Question about the coordinator in sources and why it causes segfault HOT 5
- Q: optional thread pool interface
- action_tailrecurser condition explanation
- Example test under Rx/v2/examples/tests fails
- `std::aligned_storage` is deprecated in C++23
- Docs for flat_map should reference concat_map but instead reference flat_map HOT 1
- Const overload of resource::get()
- Docs for rxcpp::sources::range are the same as those from rxcpp::observable<>::create
- identity_current_thread is bad "default" scheduler for operators
- error: unknown type name 'stdscr' auto timeout(AN&&... an) const
- Segmentation fault in case of using new_thread + current_thread
- combine_latest fails build with MSVC 19.34.31935.0 when C++ standard is set to 17 HOT 3
- Documentation request: provide examples for C++ that match examples from the "Intro to Rx" article HOT 2
- README doesn't explain how to run tests
- `find_package(rxcpp "4.1.1" CONFIG REQUIRED)` fails because CMake module version is not updated
- Create iterate error commit 562 "[Perfomance] Significantly reduce amount of copies/moves inside operators"
- run_loop dispatch optimization
- `is_hashable` is broken in C++20 (`std::hash<T>::result_type` and `::argument_type` were removed)
- Merge scheduler
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxcpp.