-
Notifications
You must be signed in to change notification settings - Fork 159
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 mapToVoid
operator
#129
Conversation
Hey, thanks for the idea !
We're not really saving so much letter count with this very specific method. WDYT? |
I had something similar in most projects that I worked on, so it feels like a common thing to use. I agree that it's not saving much letter space, but the main purpose of this extension is to explicitly mark muting the upstream. Practical example. Imagine that you want to refresh some app data in one of 4 cases:
Here is how I would implement this using Publishers.Merge4(
$addressInfo.removeDuplicates().mapToVoid(),
refreshControlPublisher.mapToVoid(),
refreshTimerPublisher.mapToVoid(),
NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification).mapToVoid()
)
// Published value type here is Void
.throttle(for: 4, scheduler: DispatchQueue.main, latest: true)
.sink {
// schedule app data refresh
}
.store(in: &cancellables) Is's more of a convenience method, but I feel like it's a good fit for Combine |
fc146fd
to
f52cc22
Compare
Codecov Report
@@ Coverage Diff @@
## main #129 +/- ##
==========================================
+ Coverage 95.50% 95.55% +0.04%
==========================================
Files 68 68
Lines 3781 3866 +85
==========================================
+ Hits 3611 3694 +83
- Misses 170 172 +2
Continue to review full report at Codecov.
|
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.
I'll go for it :) one fix
Co-authored-by: Shai Mishali <freak4pc@gmail.com>
@freak4pc do you have any further suggestions? To me looks like it's good to merge, can you do that? 🙏 |
After fixing a
mapToValue
operator I got an idea to addmapToVoid
operator. It's the most common use case for mapping publisher to a constant value. For example if you subscribe toNotificationCenter
publisher and do not care about the value it produces: