-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: EditDiff extension method for IObservable<Optional<T>> #739
Feature: EditDiff extension method for IObservable<Optional<T>> #739
Conversation
Codecov Report
@@ Coverage Diff @@
## main #739 +/- ##
==========================================
+ Coverage 72.22% 72.43% +0.20%
==========================================
Files 217 220 +3
Lines 11057 11154 +97
==========================================
+ Hits 7986 8079 +93
- Misses 3071 3075 +4
|
I also have an implementation for the inverse of this operation that I am considering submitting because I find it to be very useful. Something like: It's similar to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks
@dwcullop annoyingly there's a merge conflict here. |
That's on me for submitting so many (similar) PRs at once, but I had to get them out while I had the inspiration. I'll resolve the conflicts, no worries. |
It worked out for the best anyway because the implementation was too complicated. The whole point of this specialization is that it can be lighter weight (compared to using the IEnumerable version), but it still ended up using a bunch of Rx operators that weren't strictly needed. I updated the implementation to make it as thin as possible (only operator is Synchronize). It's a lot less code and is easier to read as well. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Similar to #738, this is an overload that operates on
IObservable<Optional<T>>
instead ofIObeservable<IEnumerable<T>>
. It is useful because it provides yet another way to have child-change sets (and also works nicely withMergeManyChangeSets
as seen below).When the first Optional with a value is observed, an Add change is emitted. When an empty Optional is observed, a Remove change is emitted for the previously Added value. If a non-empty Optional is observed, the Keys are computed and compared to determine if either a single Update (keys are the same) or a Remove/Add pair of Updates (keys are different) should be emitted.
Rationale
Since
Optional
is essentially a container with at most one value, the same behavior could be easily done with #738 and a helper function such as:However, using such an approach will result in using an entire SourceCache that is essentially empty. This specialized version is optimized around only having to deal with a single value at a time and is extremely light weight.
Example