RxSwiftExt: `merge(with:)` breaks RxSwift's `merge()`

Hi, I’ve stumbled upon an issue where importing RxSwiftExt breaks behavior of Observable.of(...).merge().

Given the following sample code:

Observable.of(a, b)
  .merge()
  .debug("+++ TEST")
  .subscribe(onNext: { x in
    print("BOO \(x)")
  })
  .disposed(by: disposeBag) // disposeBag is declared somewhere else and should retain the observable

  a.onNext("a")
  b.onNext("b")

Now, depending on whether I import RxSwiftExt or not produces drastically different result.

First, output without RxSwiftExt, everything works as expected:

+++ TEST -> Event next(a)
BOO a
+++ TEST -> Event next(b)
BOO b

Next, if I import RxSwiftExt, result is something completely unexpected. I get event completed and whole thing disposed at the end:

+++ TEST -> subscribed
+++ TEST -> Event next(RxSwift.PublishSubject<Swift.String>)
BOO RxSwift.PublishSubject<Swift.String>
+++ TEST -> Event next(RxSwift.PublishSubject<Swift.String>)
BOO RxSwift.PublishSubject<Swift.String>
+++ TEST -> Event completed
+++ TEST -> isDisposed

In fact, if I step into merge() when RxSwiftExt is imported, it actually goes inside merge(with:) method.

I can reliably reproduce this with RxSwift 5.0.1 and RxSwiftExt 5.1.1, both built with Carthage using Xcode 10 (10G8) and Xcode 11 GM 2 (11A491c).

Is this expected behavior or am I doing something wrong here?

I’m attaching a sample project I used to pinpoint the issue, please run carthage bootstrap to install RxSwift and RxSwiftExt.

merge-issue.zip

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (20 by maintainers)

Most upvoted comments

Thanks @freak4pc! 🍻

@freak4pc Concur with @akolov; the mergeWithArray branch fixed my build. 🎉

Apologies, again, for the delay!

the former isn’t great because we already have zip(with:) Would converting to an array work here ? Seems reasonable to me.