Created
July 4, 2017 08:29
-
-
Save tranhieutt/ccb5bd74b994c5f1287125da6c763f81 to your computer and use it in GitHub Desktop.
[Swift] - flatmap
This file contains hidden or 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 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