在Swift中有一个对应的平台在Scala,Xtend,Groovy,Ruby和co?
var aofa = [[1,2,3],[4],[5,6,7,8,9]] aofa.flatten() // shall deliver [1,3,4,5,9]
当然我可以使用减少为那,但是那种吸
var flattened = aofa.reduce(Int[]()){ a,i in var b : Int[] = a b.extend(i) return b }
Swift 3.0
减少:
let numbers = [[1,9]] let reduced = numbers.reduce([],+)
flatMap:
let numbers = [[1,9]] let flattened = numbers.flatMap { $0 }
加入:
let numbers = [[1,9]] let joined = Array(numbers.joined())