What is the output?
enum E: Error { case bad }
let r = Result<Int, E>.success(8)
let v = r.map { $0 + 1 }
print(try? v.get())
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
Optional(9)
Explanation:
Result.map transforms the success value (8 becomes 9), leaving failure cases unchanged. The try? safely unwraps, returning Optional(9).
[/spoiler]