Avatar
Author icon
kishikawakatsumi
let rows: [(id: Int, name1: String, name2: String)] = [ (0, "x", "y"), (1, "z", "w") ] let results1 = rows.flatMap { row in var entries = [(Int, String)]() entries.append((row.id, row.name1)) entries.append((row.id, row.name2)) return entries }
Version:
swift-5.1-RELEASE
Output:
Error:
/usercode/main.swift:10:12: error: cannot convert return expression of type '[(Int, String)]' to return type 'String?' return entries ^~~~~~~ /usercode/main.swift:6:21: error: 'flatMap' has been renamed to 'compactMap(_:)': Please use compactMap(_:) for the case where closure returns an optional value let results1 = rows.flatMap { row in ^~~~~~~ compactMap Swift.Collection:3:17: note: 'flatMap' was obsoleted in Swift 5.0 public func flatMap(_ transform: (Self.Element) throws -> String?) rethrows -> [String] ^