-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add CompositeEventSourceBuilder #28
Add CompositeEventSourceBuilder #28
Conversation
We currently have MergedEventSource to compose multiple event sources with the same event type, but it’s unergonomic because it takes an array of event sources, but you can’t construct an array of heterogeneous event sources due to limitations on protocols with associated types. The current workaround is to explicitly wrap the members of the array in AnyEventSource, but explicit use of type erasure in clients is unpleasant. Using a builder lets us take each individual event source as a generic parameter and handle the type erasure internally. I called it CompositeEventSourceBuilder rather than MergedEventSource by analogy to CompositeDisposable.
952166e
to
6f680f4
Compare
/// Builds an event source that composes all the event sources that have been added to the builder. | ||
/// | ||
/// - Returns: An event source which represents the composition of the builder’s input event sources. The type | ||
/// of this source is an implementation detail; consumers should avoid spelling it out if possible. |
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.
In particular, I’d like the return type to be some EventSource<.Event == Event>
, but Swift 5.1 will only have unconstrained opaque types.
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.
API and implementation look good to me!
Now with unit tests. In order to let the existing |
e662dea
to
2755c9f
Compare
2755c9f
to
7fb96ff
Compare
Codecov Report
@@ Coverage Diff @@
## master #28 +/- ##
==========================================
+ Coverage 96.9% 96.96% +0.06%
==========================================
Files 35 36 +1
Lines 839 858 +19
==========================================
+ Hits 813 832 +19
Misses 26 26
Continue to review full report at Codecov.
|
We currently have
MergedEventSource
to compose multiple event sources with the same event type, but it’s unergonomic because it takes an array of event sources, and you can’t construct an array of heterogeneous event sources due to limitations on protocols with associated types.The current workaround is to explicitly wrap the members of the array in
AnyEventSource
, but explicit use of type erasure in clients is unpleasant.Using a builder lets us take each individual event source as a generic parameter and handle the type erasure internally.
I called it
CompositeEventSourceBuilder
rather thanMergedEventSourceBuilder
by analogy toCompositeDisposable
.