Swift Combine CompactMap vs flatMap

map vs compactMap vs flatMap

First We see the code

map battle

CompactMap filter ‘nil’

And you use .publish. it will send the value one by one.

But you want replace “nil” to some value. Try this one.

FlatMap is more

ps. flatMap in Combine, the error type of the new publisher must match that of the source publisher.

Next one for more flatMap ~~!

happy coding

--

--

Major in physical education. Football referee. And high interest in looking the world through the numbers.

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
Mario tsai

Major in physical education. Football referee. And high interest in looking the world through the numbers.