Swift语言有很多函数式编程的特性，常见的map，reduce，filter都有，初看和python差不多，下面简单介绍下

###闭包介绍：

`func square(a:Float) -> Float { return a * a}func cube(a:Float) -> Float { return a * a * a}func averageSumOfSquares(a:Float,b:Float) -> Float { return (square(a) + square(b)) / 2.0}func averageSumOfCubes(a:Float,b:Float) -> Float { return (cube(a) + cube(b)) / 2.0}`

`func averageOfFunction(a:Float,b:Float,f:(Float -> Float)) -> Float { return (f(a) + f(b)) / 2}averageOfFunction(3, 4, square)averageOfFunction(3, 4, cube)`

`averageOfFunction(3, 4, {(x: Float) -> Float in return x * x})averageOfFunction(3, 4, {x in return x * x})averageOfFunction(3, 4, {x in x * x})averageOfFunction(3, 4, {\$0 * \$0})`

###Map

`let intArray = [1,111,1111]//结果为［"1","11","111"］let stringArray = intArray.map({ (intValue) -> String in return "(intValue)"})`

###Filter
filter用于选择数组元素中满足某种条件的元素。

`//结果[111,1111]let filterArray = intArray.filter { (intValue) -> Bool in return intValue > 30}`

###Reduce
reduce方法把数组元素组合计算为一个值。

`//结果1223let sum = intArray.reduce(0,combine: +)let sum2 = intArray.reduce(0) { (int, int2) -> Int in return int+int2}`
``` ```