-
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
🎉 withLatestFrom
for more than one publisher.
#22
🎉 withLatestFrom
for more than one publisher.
#22
Conversation
Hey @jdisho, first of all thank you so much for your work. TBH I have some issues with adding something like this:
I’m all for keeping this issue open to see if there’s more practical interest in adding this, and also to think a bit more if this is a good fit for this library. Makes sense to you? WDYT? |
Hey @freak4pc, thanks for your explanation. We can leave it open and see if other folks have different opinions. 😄 However, can you elaborate a bit more on your points? B/c, I don't fully understand them. 😇
|
What does @jasdev think? 🤓 |
|
IMO, the user of this operator shouldn't care about the implantation details. I think what's important is the operator's description to match the expectations. If this is an option, we can create |
Ok, I thought of it some more, I think this could be an OK addition. I'd be happy to get more opinions though. |
/// Upon an emission from self, emit the latest value from the | ||
/// second and third publisher, if any exists. | ||
/// | ||
/// - parameter other: A second publisher source. | ||
/// - parameter other1: A third publisher source. | ||
/// | ||
/// - returns: A publisher containing the latest value from the second and third publisher, if any. | ||
func withLatestFrom<Other, Other1>(_ other: Other, | ||
_ other1: Other1) | ||
-> AnyPublisher<(Self.Output, Other.Output, Other1.Output), Failure> | ||
where Other: Publisher, Other1: Publisher, Other.Failure == Failure, Other1.Failure == Failure { | ||
let combined = combineLatest(other, other1) | ||
.eraseToAnyPublisher() | ||
return withLatestFrom(combined) | ||
.eraseToAnyPublisher() | ||
} |
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 think we can go down this road:
/// Upon an emission from self, emit the latest value from the | |
/// second and third publisher, if any exists. | |
/// | |
/// - parameter other: A second publisher source. | |
/// - parameter other1: A third publisher source. | |
/// | |
/// - returns: A publisher containing the latest value from the second and third publisher, if any. | |
func withLatestFrom<Other, Other1>(_ other: Other, | |
_ other1: Other1) | |
-> AnyPublisher<(Self.Output, Other.Output, Other1.Output), Failure> | |
where Other: Publisher, Other1: Publisher, Other.Failure == Failure, Other1.Failure == Failure { | |
let combined = combineLatest(other, other1) | |
.eraseToAnyPublisher() | |
return withLatestFrom(combined) | |
.eraseToAnyPublisher() | |
} | |
/// Upon an emission from self, emit the latest value from the | |
/// second and third publisher, if any exists. | |
/// | |
/// - parameter other: A second publisher source. | |
/// - parameter other1: A third publisher source. | |
/// | |
/// - returns: A publisher containing the latest value from the second and third publisher, if any. | |
func withLatestFrom<Other: Publisher, Other1: Publisher>(_ other: Other, | |
_ other1: Other1) | |
-> Publishers.WithLatestFrom<Self, | |
AnyPublisher<(Other.Output, Other1.Output), Self.Failure>, | |
(Self.Output, Other.Output, Other1.Output)> | |
where Other.Failure == Failure, Other1.Failure == Failure { | |
let combined = other.combineLatest(other1) | |
.eraseToAnyPublisher() | |
return withLatestFrom(combined, resultSelector: { ($0, $1.0, $1.1) }) | |
} |
Codecov Report
@@ Coverage Diff @@
## master #22 +/- ##
==========================================
+ Coverage 96.72% 97.37% +0.65%
==========================================
Files 34 38 +4
Lines 1617 2246 +629
==========================================
+ Hits 1564 2187 +623
- Misses 53 59 +6
Continue to review full report at Codecov.
|
withLatestFrom
for more than one publisher.withLatestFrom
for more than one publisher.
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.
This looks great! I literally only have a super-tiny comment, you did a really stellar job on this PR 👏👏👏
Very detail-oriented.
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.
Oh wait, I just realized you're missing README.md updates :)
Mind taking care of those @jdisho ?
Always forget that! 😄 |
Do you have time to finish the README here? I'm happy to wrap it for you. Let me know ;) |
Working on it now 🤗 |
f52695a
to
1826a29
Compare
README.md
Outdated
@@ -74,9 +74,11 @@ github "CombineCommunity/CombineExt" | |||
|
|||
This section outlines some of the custom operators CombineExt provides. | |||
|
|||
### withLatestFrom | |||
## withLatestFrom |
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.
oops?
README.md
Outdated
Merges two publishers into a single publisher by combining each value from `self` with the _latest_ value from the second publisher, if any. | ||
### withLatestFrom(_:) | ||
|
||
Merges **two** publishers into a single publisher by combining each value from `self` with the _latest_ value from the second publisher, if any. |
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.
Let's not add specific documentation per-overload:)
We should just expand withLatestFrom mentioning it supports overloads of up to 4 observables
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 updated te README based on this comment and I hope I got it right. Should it be fine now? 😄
1826a29
to
eb08832
Compare
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.
Minor note but looks greattt
I'm working on creating
withLatestFrom
operators that support more than one publisher.In RxSwift, I face many scenarios where I need to get the latest values from more than one observable and additionally there is this great thread.
Since under the hood, I'm using
combineLatest
, I'm supporting as many publishers as the operator supports (up to four).