Swift Combine: merge() operator

Let’s go ahead and take a look at another combining operator and this is called merge operator.

merge() operator, just as the name implies, is going to merge the different events from different publishers.

merge()

I prepared two publishers. Note that if you want to merge publishers, the both publishers should have the same type. In this case, <Int, Never> is indicating the same type.

By simply calling merge(publisher), you can now receive events from the both publishers.

You can simply check that when you publisher an event with publisher1, its values will come through .sink, likewise when you emit a value from publisher2 , it also goes down to sink.

Conclusion

  • merge() operator allows you to merge multiple publihsers.
  • You can receive events from merged publisher.

--

--

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
KD Knowledge Diet

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!