🎉 withLatestFrom for more than one publisher.#22
🎉 withLatestFrom for more than one publisher.#22freak4pc merged 10 commits intoCombineCommunity:masterfrom
withLatestFrom for more than one publisher.#22Conversation
|
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.
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.
|
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
| This section outlines some of the custom operators CombineExt provides. | ||
|
|
||
| ### withLatestFrom | ||
| ## withLatestFrom |
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.
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.
I updated te README based on this comment and I hope I got it right. Should it be fine now? 😄
1826a29 to
eb08832
Compare
freak4pc
left a comment
There was a problem hiding this comment.
Minor note but looks greattt

I'm working on creating
withLatestFromoperators 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).