Skip to content

Instantly share code, notes, and snippets.

@Marcocanc
Created December 18, 2017 11:14
Show Gist options
  • Save Marcocanc/262a55d1d870370acce96ed7d113b83e to your computer and use it in GitHub Desktop.
Save Marcocanc/262a55d1d870370acce96ed7d113b83e to your computer and use it in GitHub Desktop.
Filter with KeyPath
extension Array {
func filter<T: Equatable>(where keyPath: KeyPath<Element, T>, equals compareValue: T) -> [Element] {
return filter { $0[keyPath: keyPath] == compareValue }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment