Type U comes from the parameter f to the map function. Therefore, if you pass a closure that returns Int , then map returns a Int? . If you pass the closure that Array<Int> returns, then map returns Array<Int>? .
For example, try the following:
var opt1: Optional<Int> = .Some(1) var opt2 = opt1.map { (i: Int) -> String in return "String: \(i)" }
You will find that opt1 is Int? and opt2 is String? .
source share