Skip to content

Instantly share code, notes, and snippets.

@canapio
Created March 3, 2017 12:02
// Overload 1: optional, escaping
func transform(_ n: Int, with f: ((Int) -> Int)?) -> Int {
print("Using optional overload")
guard let f = f else { return n }
return f(n)
}
// Overload 2: non-optional, non-escaping
func transform(_ input: Int, with f: (Int) -> Int) -> Int {
print("Using non-optional overload")
return f(input)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment