Title: Review and suggestions · Issue #4 · stealthcode/RxJavaMulti · GitHub
Open Graph Title: Review and suggestions · Issue #4 · stealthcode/RxJavaMulti
X Title: Review and suggestions · Issue #4 · stealthcode/RxJavaMulti
Description: Although I don't see any use in my work for such multi-observables currently, the idea about having higher arity dataflows made me interested (scientifically) in this library. Here, I'd like to write some points I see about such library....
Open Graph Description: Although I don't see any use in my work for such multi-observables currently, the idea about having higher arity dataflows made me interested (scientifically) in this library. Here, I'd like to wri...
X Description: Although I don't see any use in my work for such multi-observables currently, the idea about having higher arity dataflows made me interested (scientifically) in this library. Here, I'd lik...
Opengraph URL: https://github.com/stealthcode/RxJavaMulti/issues/4
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Review and suggestions","articleBody":"Although I don't see any use in my work for such multi-observables currently, the idea about having higher arity dataflows made me interested (scientifically) in this library. Here, I'd like to write some points I see about such library.\n## Approach\n\nFirst, Instead of creating Bi- and Tri- Observables by hand, you can explore the possibility of code templating and static code generation, similar how many of the primitive-collections libraries (such as Trove or fastutil) do it.\n\nSecond, I suggest adopting the reactive-streams idioms instead of the RxJava 1.x idions. I don't see too much direct code reuse and since you'll need wrappers and converters anyway, you have the opportunity to avoid a few less-than-optimal decisions the RxJava API has made.\n## Primitives\n\nI'd start a new type hierarchy based on the reactive-streams idioms:\n\n``` java\ninterface {Arity}Publisher\u003cTi, ...\u003e {\n void subscribe({Arity}Subscriber\u003cTi, ...\u003e s);\n}\ninterface SubscriberBase {\n void onStart(Subscription s);\n void onError(Throwable e);\n void onCompleted();\n}\ninterface {Arity}Subscriber\u003cTi, ...\u003e extends SubscriberBase {\n void onNext(T1 t1, ...);\n}\ninterface Subscription { // or import reactive-streams directly\n void request(long n);\n void cancel();\n}\ninterface {Arity}Processor\u003cTi, ..., Ri, ...\u003e extends\n {Arity}Subscriber\u003cTi,...\u003e, {Arity}Publisher\u003cRi, ...\u003e {\n} \n```\n## Queues\n\nSince most operators require some Spsc queue to operate and they are designed to transmit one element at a time, you'll need to extend the logic and API of the classical Queues.\n\n``` java\ninterface {Arity}Queue {\n boolean offer(Ti, ...);\n boolean poll(Action{k}\u003cTi, ...\u003e out); // true if element was available\n boolean peek(Action{k}\u003cTi, ...\u003e out);\n boolean isEmpty();\n int size();\n}\n```\n\nNote that indeed, using callbacks poses some overhead, but I think it is less than allocating some tuples for the classical queues.\n\nIn addition, the ring-buffer based Spsc queue implementation needs some slight changes regarding the element store: you can use the current indexing logic, but now that translates to k-times indexing into the underlying array (the power-of-2 remains), roughly:\n\n``` java\nObject[] array = new Object[powerOf2Capacity * 3];\n\nvoid offer(T1 t1, T2 t2, T3 t3) {\n int offset = ((int)(producerIndex) \u0026 mask) * 3;\n array[offset] = t1;\n array[offset + 1] = t2;\n array[offset + 2].lazySet(t3); // memory order: release\n producerIndex++;\n}\nboolean poll(Action3\u003cT1, T2, T3\u003e out) {\n int offset = ((int)(consumerIndex) \u0026 mask) * 3;\n Object o3 = array[offset + 2]; // memory order: acquire\n if (o1 == null { return false; }\n Object o2 = array[offset + 1]; // read in opposite order\n Object o1 = array[offset];\n array[offset] = null;\n array[offset + 1] = null;\n array[offset + 2].lazySet(null);\n consumerIndex++;\n out.call((T1)o1, (T2)o2, (T3)o3);\n return true;\n}\n```\n## Callbacks on the stream\n\nSince Java functions can't return more than one result, one can return a tuple for each 'column' and split the operators into many, or use the same trick as with queues and have an output callback:\n\n``` java\npublic final BiObservable\u003cR1, R2\u003e map(Action3\u003c? super T1, ? super T2, Action2\u003cR1, R2\u003e\u003e mapper) {\n return lift(s -\u003e {\n return new AbstractBiSubscriber\u003cT1, T2\u003e(s) {\n @Override\n public void onNext(T1 t1, T2 t2) {\n mapper.call(t1, t2, s::onNext);\n }\n // ...\n });\n });\n}\n```\n","author":{"url":"https://github.com/akarnokd","@type":"Person","name":"akarnokd"},"datePublished":"2015-06-13T12:06:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/4/RxJavaMulti/issues/4"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7074a6fe-dc3c-6866-12e1-e1d504f27c85 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A03A:361504:304A5A3:4135F03:697306C2 |
| html-safe-nonce | 64805ac90589554dcc2a034879f5e6171bbf9514536c48ee5aa6a7b8de2e4dfa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDNBOjM2MTUwNDozMDRBNUEzOjQxMzVGMDM6Njk3MzA2QzIiLCJ2aXNpdG9yX2lkIjoiNTE2Nzk1MTUxODQ0NjU4NTUzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bebe33045879d17a0e3521352f3394a58c15cf0c4c496d64ea7e94e2c20cc350 |
| hovercard-subject-tag | issue:87993885 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/stealthcode/RxJavaMulti/4/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e405d6b40e19058b40eeb4d9a2fdd89d19978346f884897e93a9839a3d92c1cd/stealthcode/RxJavaMulti/issues/4 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e405d6b40e19058b40eeb4d9a2fdd89d19978346f884897e93a9839a3d92c1cd/stealthcode/RxJavaMulti/issues/4 |
| og:image:alt | Although I don't see any use in my work for such multi-observables currently, the idea about having higher arity dataflows made me interested (scientifically) in this library. Here, I'd like to wri... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | akarnokd |
| hostname | github.com |
| expected-hostname | github.com |
| None | 44ab3188c1dcfe3be0f9c3feca2e04e14fb79f120939ce2395e4f15ab96ec1d4 |
| turbo-cache-control | no-preview |
| go-import | github.com/stealthcode/RxJavaMulti git https://github.com/stealthcode/RxJavaMulti.git |
| octolytics-dimension-user_id | 1455238 |
| octolytics-dimension-user_login | stealthcode |
| octolytics-dimension-repository_id | 28906678 |
| octolytics-dimension-repository_nwo | stealthcode/RxJavaMulti |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 28906678 |
| octolytics-dimension-repository_network_root_nwo | stealthcode/RxJavaMulti |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a5e2b48bd1260476599758f5d253b5d24092ab84 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width