Group Group Group Group Group Group Group Group Group

Programming in Swift: Functions and Types · Challenge: Closures | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5429279-programming-in-swift-functions-and-types/lessons/11

I don’t understand the part about things that can only be done in a closure instead of a function. The Pythagorean theorem example shows
printResult({ (a, b) -> Double in
ab
}, 3, 4)
But can’t this be done with the following function?
func pythagorean(a: Double, b: Double) -> Double {
return ((a
a) + (b*b)).squareRoot()
}
pythagorean(a: 5, b: 3)