Skip to content

Instantly share code, notes, and snippets.

@ldct
Created March 27, 2024 19:38
Show Gist options
  • Save ldct/c5ebb23a074ebc7dd9a56fc8ad309f24 to your computer and use it in GitHub Desktop.
Save ldct/c5ebb23a074ebc7dd9a56fc8ad309f24 to your computer and use it in GitHub Desktop.
func sum(a: Int?, b: Int?) -> Int? {
a.flatMap({ unwrappedA in
b.flatMap({ unwrappedB in
.some(unwrappedA + unwrappedB)
})
})
}
func sum(_ a: [Int], _ b: [Int]) -> [Int] {
a.flatMap({ unwrappedA in
b.flatMap({ unwrappedB in
[unwrappedA + unwrappedB]
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment