【发布时间】:2016-03-30 17:59:05
【问题描述】:
我想编写一个可以链接到 map { } 函数的函数。例如:
let arr = [1,2,3,4,5]
let list = arr.map { $0 * 2 }.applyRuleToSubtractVal(1) // return [1,3,5,7,9]
我如何定义上面的applyRuleToSubtractVal()? (我想做更复杂的事情,不想在地图里面做。)
【问题讨论】:
-
你不需要在“the”
map里面做事情,你可以链接map,比如arr.map { $0 * 2 }.map { do_something_complex($0) }.map { $0 + 1 }。
标签: swift functional-programming higher-order-functions map-function