Created
December 18, 2017 11:14
-
-
Save Marcocanc/262a55d1d870370acce96ed7d113b83e to your computer and use it in GitHub Desktop.
Filter with KeyPath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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