Seems bugged. These all compile.
func chooseStepFunction(backward: Bool) -> (Int) -> Int {
if backward { stepBackward } else { stepForward }
}
func chooseStepFunction(backward: Bool) -> (Int) -> Int {
backward ? stepBackward as (_) -> _ : stepForward
}
func chooseStepFunction(backward: Bool) -> (Int) -> Int {
backward ? stepBackward : stepForward as (_) -> _
}
This version of the code from the nested functions section compiles fine. The problem comes only with externally-scoped functions.
func chooseStepFunction(backward: Bool) -> (Int) -> Int {
func stepForward(input: Int) -> Int { return input + 1 }
func stepBackward(input: Int) -> Int { return input - 1 }
return backward ? stepBackward : stepForward
}