Comments (6)
Hi!
Thanks for feature request =)
Not sure, if i get your idea right.... to emit values via behavior_subject you need to "push" this value somehow. For example
rpp::subjects::behavior_subject<std::map<std::string, std::pair<double, double>>> subj;
subj.get_observer.on_next(?????);
So, target expected value anyway is constructed during on_next
stage.
What you are requesting is kind of scan but with caching, right?
rpp::subjects::publish_subject<double> some_inner_subject;
auto observable = some_inner_subject.get_observable()
| rpp::operators::scan(std::map<std::string, std::pair<double, double>>{},
[](auto&& map, double value) {
// some complex rule
map[std::to_string(value)] = std::pair{value, value};
return map;
});
some_inner_subject.get_observer().on_next(1);
// Expected to obtain {{"1":{1,1}} ??????
observable.subscribe([](auto v) { .....});
some_inner_subject.get_observer().on_next(2);
// Expected to obtain {"1":{1,1}, "2":{2,2}} ??????
observable.subscribe([](auto v) { .....});
Anyway, do you have any ideas how it can be manipulated from user's perspective?
from reactiveplusplus.
Hi! Thanks for feature request =)
Not sure, if i get your idea right.... to emit values via behavior_subject you need to "push" this value somehow. For example
True, and each time I push a new value, I have to construct the entire object, which might be expensive. Image this previously mentioned map, which might contain many many elements. So, each time I want to emit a new map where only one entry changed, I have to copy the whole map for changing only a single entry.
Anyway, do you have any ideas how it can be manipulated from user's perspective?
Hmm, good question.
When I check the source of v1's behavior_subject, there is a getter for the value: get_value. One could return a reference to the internal state value.
Then we need something like on_next_with_latest_state() or similar....
Not sure, if this can help (or inspire), but i am also using Kotlin Flow and I definitely prefer this over RxJava (and the strict syntax of Rx).
from reactiveplusplus.
Hmm, i see your issue. Looks like it should be custom operator or something like this... i don't think it is good idea to provide ability to modify subject's state directly - it is unsafe and doesn't follow "functional" way.
Isn't it enough to make something like...
auto new_map = subject.get_value();
new_map[some_key].some_value = some_new_value;
subject.on_next(std::move(new_map));
It can be easily wrapped to custom operator if you prefer it. Or such an solution is missing something?
from reactiveplusplus.
Understood your concerns. My current solution is exactly what you described and this is perfectly reasonable for small maps (and probably even bigger ones).
Afaik, java (and other languages) do not do deep copies and calling on_next on an object would not result in a deep copy. However, it seems to be that way in C++. Alternatively, I could create a pointer and use that as the subject's type....
Not sure, about the custom operator, though.
from reactiveplusplus.
Afaik, java (and other languages) do not do deep copies and calling on_next on an object would not result in a deep copy.
In my understanding, all variables in garbage collector based languages are kind of shared_ptrs....
However, it seems to be that way in C++.
To be honest, current example would make 1 copy from get_value()
and 1 move inside on_next
. Not to much =)
Alternatively, I could create a pointer and use that as the subject's type....
Yeah, shared_ptr also the option in this case. Not such an elegant, but no any copies would happen at all... =)
from reactiveplusplus.
Looks like no any actions required there
from reactiveplusplus.
Related Issues (20)
- Create pool based schedulers: IO and Computation HOT 5
- Re-implement scheduler's related code
- Implement debounce operator
- Add average operator (and other statistical) HOT 3
- Question about sample_with_time (oversampling) HOT 5
- Add window_with_time operator
- Add buffer_with_time operator
- Consider pushing builds to NUGet HOT 1
- RPP v2 - Implementation Status
- Two broken links HOT 1
- Feature request for "Single-Observable" HOT 2
- Create another v1 release HOT 8
- Resolve "nano sleeps" HOT 5
- Throttle operator HOT 3
- Publish subject fails compilation on GCC 13 HOT 2
- Limit memory growing for window/concat/merge operators
- creating an observable from C callback functions HOT 7
- Reemit from subscription HOT 3
- How to refer to observable type anyway? HOT 2
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 reactiveplusplus.