Skip to content

Instantly share code, notes, and snippets.

@edopelawi
Created September 13, 2016 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edopelawi/a1a23f4cff9797391af1a3973a8a64d7 to your computer and use it in GitHub Desktop.
Save edopelawi/a1a23f4cff9797391af1a3973a8a64d7 to your computer and use it in GitHub Desktop.
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