Created
September 13, 2016 16:02
-
-
Save edopelawi/a1a23f4cff9797391af1a3973a8a64d7 to your computer and use it in GitHub Desktop.
Another sample on using flatMap on an array of Optionals.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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