Изменения в новых версиях / Swift 4.1

let strings = ["1""two""3"]

// *** before: ***
// one name did two different jobs, and the reader had to guess which one
let numbersOld = strings.flatMap { Int($0) }      // dropping nil
let flatOld = [[12], [3]].flatMap { $0 }        // flattening

// *** in version 4.1: ***
let numbers = strings.compactMap { Int($0) }      // [1, 3]
let flat = [[12], [3]].flatMap { $0 }           // [1, 2, 3], only flattening

let optionals: [Int?] = [1nil3]
print(optionals.compactMap { $0 })                // [1, 3]

// the old flatMap over optionals is deprecated and warns