iOS ● ● ○ Swift 6

Kodebits Day 21: Result Map Value

May 11 2026
Practice error handling with a short swift challenge.

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]


Further Reading