Skip to content

Instantly share code, notes, and snippets.

@dineshba
Last active May 20, 2018 14:09
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 dineshba/c62e5414975876d3b063c84afa17664b to your computer and use it in GitHub Desktop.
Save dineshba/c62e5414975876d3b063c84afa17664b to your computer and use it in GitHub Desktop.
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