Last active
April 16, 2020 07:18
-
-
Save Alexander-Ignition/e5479379a872f8c297b9e97ab448363d to your computer and use it in GitHub Desktop.
KeyPath filter
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
| func == <T, U>( | |
| keyPath: KeyPath<T, U>, | |
| value: U | |
| ) -> (T) -> Bool where U: Equatable { | |
| return { $0[keyPath: keyPath] == value } | |
| } | |
| struct User { | |
| let name: String | |
| } | |
| func test() { | |
| let user = User(name: "x") | |
| [user].filter(\.name == "x") | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment