Am I correct in thinking that your complaint is essentially that flatMap() is not equivalent to map() followed by flatten()?Sometimes it's described that way (by other comments in the stdlib), but in the case where the supplied transform produces an Optional, the flatten() seems to be replaced by a non-nil filter and unwrapping. flatten() does not seem to be defined on Optionals, nor on sequences of Optionals, so the follow-up operation performed by flatMap() in the case of optional-producing transforms has no apparent relationship to flattening.If that's the crux of your argument, I agree; the current definitions seem inconsistent and kind of random to me. But I don't have much background in FP. You mention that Swift's flatMap() seems similar to that of Scala. So what's Scala's excuse?
Topic:
Programming Languages
SubTopic:
Swift
Tags: