Given:
let maybeNumbers: [Int?] = [1,2,3,nil,5]
let numbers = maybeNumbers.flatMap { $0 }
print(numbers)
=> [1, 2, 3, 5]
Where flatMap on a SequenceType is said to:
Return an Array containing the non-nil results of mapping transform over self.
- cite
What is the output of
var a = [[1,2],[3,4]]
a = a.flatMap { $0 }
var b = a.flatMap { $0 }
print(a)
print(b)