1
dorentus 2015-10-10 16:08:00 +08:00
说说哪里丑陋了?
|
2
expkzb OP @dorentus 比如这种东西
func jediTrainer () -> ((String, Int) -> String) { func train(name: String, times: Int) -> (String) { return "\(name) has been trained in the Force \(times) times" } return train } let train = jediTrainer() train("Obi Wan", 3) 操作符太多,也过于抽象,个人认为不太符合编程语言发展的趋势 |
3
dorentus 2015-10-10 18:00:54 +08:00
func jediTrainer()(name: String, times: Int) {
return "\(name) has been trained in the Force \(times) times" } 这样看着是不是舒服些? |
4
dorentus 2015-10-10 18:08:08 +08:00 via iPhone
另外通常情况下比较少会遇到一定要这么做的,如果一定要这么做那么你肯定有使用函数式语言的背景,那么理解上也不会有啥问题。
|
6
expkzb OP @dorentus
func jediTrainer()(name: String, times: Int) { return "\(name) has been trained in the Force \(times) times" } 对 swift 了解不深,这个和我的那个是等价的吗?貌似只返回了一个字符串并没有返回函数 |