嵌套函数的实际用途是什么?它只会使代码更难阅读,并且不会使特定情况变得容易.
func chooseStepFunction(backwards: Bool) -> (Int) -> Int {
func stepForward(input: Int) -> Int { return input + 1 }
func stepBackward(input: Int) -> Int { return input - 1 }
return backwards ? stepBackward : stepForward
}
Run Code Online (Sandbox Code Playgroud)