Sitemap

Swift Combine CompactMap vs flatMap

Aug 8, 2021

--

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.

Press enter or click to view image in full size

Next one for more flatMap ~~!

happy coding

--

--

SysLayer
SysLayer

Written by SysLayer

Backend system design, distilled. SQL-first guides for developers who build real products.