Last active
May 20, 2018 14:09
-
-
Save dineshba/c62e5414975876d3b063c84afa17664b to your computer and use it in GitHub Desktop.
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 fanNames = computerLab.laptops | |
.filter({laptop in !laptop.name.contains("Mac") }) | |
.filter({laptop in laptop.fan != nil}) | |
.map({laptop in laptop.fan!.name}) | |
// Simplified | |
let fanNames = computerLab.laptops | |
.filter({laptop in !laptop.name.contains("Mac") }) | |
.compactMap({laptop in laptop.fan?.name}) //compactMap will filter out nil values by default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment