map,flatMap,filter的基本使用

26. January 2016 Swift 0

[“key”:”value”].upperDescription

var result = [1,2,3,4,5].flatMap{$0 * 2;} // flatMap与map类似,但是会过滤掉返回值里面的nil值

result

var result1 = [1,2,3,4,5].map{$0 * 2} //map 得到一个由必包里面的返回值组成的新序列

result1

var ss = [1,2,3,4,5].filter{ $0 > 2} //Filter得到一个由必包返回值为true的值组成的新序列

ss


Leave a Reply

Your email address will not be published. Required fields are marked *