Swift Combine: zip() operator

Let’s take a look at zip() operator. What zip() is doing is that it’s going to pair different elements or different items from the publisher. But it’s not going to wait for the latest element from the publisher. zip() operator is simply going to pick and tries to pair depending on the values that it is receiving from the both publishers.

zip()

I prepared two publishers and zipped them. But as you can see from the code above, zipped publishers through zip() operator are not going to be called unless provided a pair. If you know combineLatest() operator, you can see the difference. With combineLatest(), when its first published value went down to the downstream, you can even receive the event from one publisher. But zip() is different because it always needs a pair of an emitted event to form a tuple value.

Conclusion

  • zip() operators combine multiple publishers.
  • zip() needs a pair of an event to emit the value.

--

--

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!