CombineCommunity / CombineExt

CombineExt provides a collection of operators, publishers and utilities for Combine, that are not provided by Apple themselves, but are common in other Reactive Frameworks and standards.
https://combine.community
MIT License
1.72k stars 151 forks source link

CombineLatestMany behavior for 0 publishers #164

Closed peteranny closed 8 months ago

peteranny commented 8 months ago

Hello, I want to confirm the CombineLatestMany behavior for 0 publishers. Unlike:

let publishers: [Just] = [Just(1), Just(2)]
model.subscription = publishers.combineLatest().sink(receiveValue: { print($0) })
// [1, 2]

Zero publishers result in

let publishers: [AnyPublisher<Int, Never>] = []
model.subscription = publishers.combineLatest().sink(receiveValue: { print($0) })
// No output

in which I would expect to have [] rather than nothing. In my case, the current behavior arose a bug in my application as I expected there would always an output no matter how many publishers. I had to manually substitute Just([]) when 0 publishers.

As noted in the CombineExt README, CombineExt was inspired by RxSwift. I just checked the behavior in RxSwift:

let observables: [Observable] = [.just(1), .just(2)]
_ = Observable.combineLatest(observables).subscribe(onNext: { print($0) })
// [1, 2]

and if 0 observables:

let observables: [Observable<Int>] = []
_ = Observable.combineLatest(observables).subscribe(onNext: { print($0) })
// []

Wonder if we would prefer aligning this case as RxSwift does?

jasdev commented 8 months ago

Some earlier discussion on this https://github.com/CombineCommunity/CombineExt/issues/118#issuecomment-1068410307

peteranny commented 8 months ago

Thank you! I searched the open issues but not the closed. I'm closing this one!