Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Another sample on using flatMap on an array of Optionals.
let duckSailors = ["Daffy", "Donald", "Howard"]
let sealSailors = ["Manatee", "Moby"]
let otherSailors = [duckSailors, sealSailors]
let flattenedSailors = otherSailors
.flatMap { nameArray -> [String] in
return nameArray
print("Flatten Sailor names: \(flattenedSailors)")
flattenedSailors.forEach { name in
print(createGreetings(sailorName: name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment