Skip to content

Instantly share code, notes, and snippets.

@Alexander-Ignition
Last active April 16, 2020 07:18
Show Gist options
  • Save Alexander-Ignition/e5479379a872f8c297b9e97ab448363d to your computer and use it in GitHub Desktop.
Save Alexander-Ignition/e5479379a872f8c297b9e97ab448363d to your computer and use it in GitHub Desktop.
KeyPath filter
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