Closed DesmanLead closed 2 years ago
Hey, I believe this was discussed already here - This behavior is matched with that of RxSwift and Reactive Streams spec. An empty publisher doesn't mean an empty value - on the contrary, it means the lack of values.
Do you have any use cases in mind when this behavior makes sense? Maybe, I'm biased by our use cases.
It's not about a use case it's about guarantees and rules of the operator :) combineLatest combines publishers once they emit at least a single value - if one of the publishers never emits anything, the entirety of the combination shouldn't. The fact it's an array and not just two or three individual publishers is just an implementation detail, the rules themselves don't change :)
Sounds reasonable, I'm convinced :)
Do you have any elegant solution in mind for the case when either all the publishers emit at least one value or there are no publishers?
I can't say I'm completely satisfied with if input.isEmpty { return Just([]).eraseToAnyPublisher() }
%)
Thanks for sharing your thoughts!
@DesmanLead: .replaceEmpty(with: [])
should do the trick. ✅
Even though Ext didn’t decide to go this route, there’s sound theoretical reason for why an empty array should be emitted. I wrote a bit about it here, if you’re curious.
Example:
Nothing will be printed if
publishers
is an empty array. Feels like the correct behavior is to emit an empty array ofString
in this case. The caller doesn't need a special handling of an empty input case then.