Repository navigation
feat(advanced): add the SwitchMap fused sink - #163
Merged
Merged
Conversation
ChrisPulman
approved these changes
Aug 15, 2026
- Add SwitchMapSignal, which projects each source value to an inner observable and mirrors the latest one in a single sink, and the SwitchMap operator over it. - Every source value switches, null included, so a caller that projects null onto its own inner observable detaches the previous one. - Reimplement SwitchSelect on the same sink, which skips nulls instead of switching on them. Its switching bookkeeping now lives in one place.
glennawatson
force-pushed
the
feat/switch-map-fused-sink
branch
from
August 15, 2026 08:17
e875c46 to
d98172f
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #163 +/- ##
==========================================
- Coverage 98.14% 98.14% -0.01%
==========================================
Files 679 680 +1
Lines 21417 21432 +15
Branches 2619 2619
==========================================
+ Hits 21020 21034 +14
Misses 197 197
- Partials 200 201 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What kind of change does this PR introduce?
Feature, plus a refactor of an existing operator onto the new sink.
What is the new behavior?
SwitchMapprojects each value to an inner observable and mirrors the latest one, in a single fused sink.SwitchMapSignal<TSource, TResult>is public inAdvanced. One object and one observer hop, where a projection followed by a separate switch costs two of each plus an intermediate sequence of observables.SwitchSelectis reimplemented on the same sink. It keeps its existing behavior of skipping nulls, which leaves the active inner subscription in place. The two now differ only in that flag; the switching bookkeeping - generation ids, the gate, the outer/inner completion interlock - exists once instead of twice.ReactiveUI.Primitives.AdvancedandReactiveUI.Primitives.Reactive.Advanced.What is the current behavior?
Reaching the latest inner observable from a projection means composing two sinks.
Select(selector).Switch()allocates the projection sink, its observer, the switch sink and its observer, and threads anIObservable<IObservable<T>>between them.SwitchSelectis the only fused form and it always skips nulls, so it cannot express a projection that switches on null.What might this PR break?
None.
SwitchMapis new API.SwitchSelectkeeps its signature and its skip-null semantics; only its implementation moved.Checklist
mainbranchAdditional information
Most of the diff is the public API baselines; two files were authored.
src/Primitives.Shared/Advanced/SwitchMapSignal{TSource,TResult}.cs- the sink.src/Primitives.Shared/SignalOperatorMixins.ChooseSwitchSelect.cs- theSwitchMapoperator, andSwitchSelectreduced to a call into the sink.src/tests/ReactiveUI.Primitives.Tests/SwitchMapTests.cs- covers switching on null, stale-inner suppression, the completion interlock, selector/outer/inner errors, and disposal.PublicAPI.Shipped.txt, inserted at its sorted position.The existing
SwitchSelecttests are unchanged and still pass, which is what pins the refactor.