当函数的返回值是另一个函数时,没有办法获得返回函数的参数名称.这是一个快速语言的陷阱吗?
例如:
func maketownGrand(budget:Int,condition: (Int)->Bool) -> ((Int,Int)->Int)? { guard condition(budget) else { return nil; } func buildroads(lightsToAdd: Int,toLights: Int) -> Int { return toLights+lightsToAdd } return buildroads } func evaluateBudget(budget:Int) -> Bool { return budget > 10000 } var stopLights = 0 if let townPlan = maketownGrand(budget: 30000,condition: evaluateBudget) { stopLights = townPlan(3,8) }
注意townPlan,townPlan(lightsToAdd:3,toLights:8)对townPlan(3,8)会更加明智,对吗?