Skip to content

Instantly share code, notes, and snippets.

@salmaanahmed
Created January 28, 2019 12:28
Show Gist options
  • Save salmaanahmed/4ea9da14a1485a35c99065c72e67daaf to your computer and use it in GitHub Desktop.
Save salmaanahmed/4ea9da14a1485a35c99065c72e67daaf to your computer and use it in GitHub Desktop.
let d: [String: String?] = ["a": "1", "b": nil, "c": "3"]
let r1 = d.filter { $0.value != nil }.mapValues { $0! }
let r2 = d.reduce(into: [String: String]()) { (result, item) in result[item.key] = item.value }
// r1 == r2 == ["a": "1", "c": "3"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment