“You’ve seen how Combine includes operators such as map that correspond and work similarly to higher-order functions found in the Swift standard library. And you’ve learned about the flatMap operator, which doesn’t work at all like its renamed counterpart.”
Flapmap respects the mathematical properties / concepts of all its counterparts. For example, flatmap on optional makes certain you get an Optional value and not Optional<Optional>, what you would get by using map. Exemple .optional(“2”).flatmap(Int.init). The same way flatmap on Result, let you have a Result and not Result<Result> when you would return a result in a map. Flatmap solves the nesting problem in general of mapping when the transformation gives the base type. flatmap here does the same so we do not nest publisher!
Thanks for bringing this up. Although flatMap in Combine does not as closely resemble the behavior of other counterparts between Combine and the Swift standard library, I see what you mean about there being a commonality regarding the mathematical aspects between the two. So I’ll remove mentioning that Combine’s flatMap doesn’t work at all like its counterpart.
Just to point out though, the publisher returned by flatMap does not — and often will not — be of the same type as the upstream publishers it receives.