Skip to content

Instantly share code, notes, and snippets.

@Qata
Created June 15, 2017 00:10
Show Gist options
  • Save Qata/9687cdbaf611cfa5fd4c3456af5c7e3e to your computer and use it in GitHub Desktop.
Save Qata/9687cdbaf611cfa5fd4c3456af5c7e3e to your computer and use it in GitHub Desktop.
extension Sequence {
func map<U>(_ keyPath: KeyPath<Element, U>) -> [U] {
return map { $0[keyPath: keyPath] }
}
func flatMap<U>(_ keyPath: KeyPath<Element, U?>) -> [U] {
return flatMap { $0[keyPath: keyPath] }
}
func flatMap<U, S: Sequence>(_ keyPath: KeyPath<Element, S>) -> [U] where S.Iterator.Element == U {
return flatMap { $0[keyPath: keyPath] }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment