[swift-evolution] [Proposal] Higher Kinded Types (Monads, Functors, etc.)

Al Skipp al_skipp at fastmail.fm
Thu Dec 17 05:58:41 CST 2015


>>> Optional.map and Array.map do different things, and unifying them seems harmful.
>> 
>> They actually don’t do different things. Optional can be thought of as an array of zero or one elements; from that point of view, operations like `map` and `flatMap` which are supported on both actually do the same thing.
> 
> I understand that reasoning, but it's completely contrary to how I (and presumably many other people) normally think. To me, optional is not a 0..1 array, it's just an optional.

> I don't want a flatMap on optionals (which, I believe, was thankfully removed in Swift 2).

Thankfully it lives : )

// useless function: return arg if less than 10, otherwise .None
func f(x:Int) -> Int? {
  return x < 10 ? x : .None
}

Int("9").map(f) // .Some(.Some(9))
Int("9").flatMap(f) // .Some(9)

Int("10").map(f) // .Some(.None)
Int("10").flatMap(f) // .None
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151217/ae64919b/attachment.html>


More information about the swift-evolution mailing list