Swift Combine: first() operator, return only a single value!

Find a single value

let numbers = (1...9).publishernumbers
.first(where: { $0 % 2 == 0 }) // what you are looking for
.sink {
print($0) //2, nothing more will be printed than 2
}

Conclusion

  • first() operator only returns a single value which meets your criteria.

--

--

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

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!