[JAVA-4311] Observable[Void] cannot be composed using monadic operations Created: 24/Sep/21 Updated: 04/May/22 Resolved: 28/Sep/21 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Scala |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Unknown |
| Reporter: | Scott Rice | Assignee: | Ross Lawley |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | external-user | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
mongo-scala-driver: 4.3.1 Operations returning Observable[Void] cannot used map, flatMap, filter, etc., since they rely on onNext being called and Observable[Void] does not call onNext. Two use cases where this is needed: 1. Returning a custom return type for operations that return Observable[Void]. For example:
The .map(_ => CustomVoidMongoResult(request, someMetaData)) does not get executed, since MapObservable relies on onNext get called, but it never is called. 2. Chaining operations returning observables together using flatMap, where one of the (non-last) operations returns Observable[Void]. Fo example:
This example uses for-comprehension syntactic sugar, where the arrows are maps and the yield is a flatMap. The last line createIndex(index) line never gets reached, since again MapObservable depends on onNext getting called. One solution would be to change ToSingleObservableVoid to ToSingleObservableUnit, like:
Unit is the Scala equivalent of Java Void, except that it can be instantiated. |
| Comments |
| Comment by Ross Lawley [ 28/Sep/21 ] |
|
Hi scott.rice@rallyhealth.com, Thanks for the ticket - we also have I'm in the process of reviewing and will take a look at your PR and that ticket and see what the best course of action is. Unfortunately, changing signatures to Observable[Unit] would be an API break and would require a major release. Please follow Ross |
| Comment by Scott Rice [ 26/Sep/21 ] |
|
This should have Component/s: Scala - noticed that after creating this ticket. Cannot edit after the fact. |
| Comment by Scott Rice [ 24/Sep/21 ] |
|
Possible solution PR - https://github.com/mongodb/mongo-java-driver/pull/788 |