Skip to content

Instantly share code, notes, and snippets.

@edopelawi
Created September 13, 2016 15:51
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/6e644100bf83d0dc98c495d9194624be to your computer and use it in GitHub Desktop.
Save edopelawi/6e644100bf83d0dc98c495d9194624be to your computer and use it in GitHub Desktop.
A sample on using flatMap for filtering out nils from an array of String optionals.
let sailorNames: [String?] = [
nil,
"Daffy Duck",
"Donald Duck",
nil,
"Darkwing Duck",
"Howard The Duck",
]
let unwrappedSailorNames = sailorNames.flatMap({ $0 })
for sailorName in unwrappedSailorNames {
print(createGreetings(sailorName: sailorName))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment