Skip to content

Instantly share code, notes, and snippets.

@tranhieutt
Created July 4, 2017 08:29
Show Gist options
  • Save tranhieutt/ccb5bd74b994c5f1287125da6c763f81 to your computer and use it in GitHub Desktop.
Save tranhieutt/ccb5bd74b994c5f1287125da6c763f81 to your computer and use it in GitHub Desktop.
[Swift] - flatmap
let collections = [[5,3,6],[5,6,8]]
let flat = collections.flatMap {$0}
print(flat)
//Console: [5, 3, 6, 5, 6, 8]
//Remove optional
let peple : [String?] = ["Tom", nil,"Teddy", nil]
let valid = peple.flatMap{$0}
//Console: ["Tom", "Teddy"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment