Skip to content

Instantly share code, notes, and snippets.

@darthpelo
Last active September 15, 2015 12:02
Show Gist options
  • Select an option

  • Save darthpelo/b764043ada8e5eafc0de to your computer and use it in GitHub Desktop.

Select an option

Save darthpelo/b764043ada8e5eafc0de to your computer and use it in GitHub Desktop.
How to implement flatMap in Swift 1.2. An idea of Berik https://github.com/berikv.
let list: [String?] = [nil, nil, "ciao", "hello", nil]
list.reduce([String]()) {
if let e = $1 {
return $0 + [e]
} else {
return $0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment