lempiji / rx

Reactive Extensions for D Programming Language
MIT License
53 stars 8 forks source link

Implement groupBy #14

Closed gizmomogwai closed 6 years ago

gizmomogwai commented 6 years ago

Hi ... I really like rx for dlang :) I want to use it in a filewatcher program to debounce events from the filesystem. Problem is, that the low-level api produces several events for a write on a file, that i want not directly published to the application. This can easily be done with e.g. rxjava by doing something like this: https://stackoverflow.com/a/43431636/204070

merge( source.groupBy(value -> value.objectId) .map(observable -> observable.debounce(1, TimeUnit.SECONDS)) )

unfortunately i do not know enough (yet) of rx for dlang to implement my own groupBy ...

lempiji commented 6 years ago

thanks for request😃

The merge overload and groupBy are missing in rx. I will think how to implement it.

Are you using fswatch package? It might be enough to use this.

To make an own Obsevable and publish value, examples around here may be helpful. https://github.com/lempiji/rx/blob/master/examples/http-client/source/app.d

gizmomogwai commented 6 years ago

Thanks for the pointer to the http-client app. I looked also a little into the java rx implementation which looks rather complicated for all the merge overloads ... actually my usecase would need an overload for a stream of observables as well. merge at the moment only has an overload for two observables?

lempiji commented 6 years ago

Yes. I only implement what merges two Observables.

I thought about an easy implementation for streamed Observables. Create a Subject, make grouped source Observables, subscribe to source and redirect to the Subject.

Perhaps the merge will also be this way. I will try on the weekend.

lempiji commented 6 years ago

I implemented groupBy. Merge for streams too. I also wrote an example, is it as expected?

https://github.com/lempiji/rx/blob/bc030718513392529f3f8add165b8acff2217e6b/examples/rx-fswatch/source/app.d

gizmomogwai commented 6 years ago

your a genius! this looks great! i will give it a try!!!

gizmomogwai commented 6 years ago

Sorry about the wrong comments (i deleted them) ... works flawless !!! Thanks a lot!

lempiji commented 6 years ago

😃