Skip to content

Instantly share code, notes, and snippets.

@samdods
Last active March 7, 2019 12:33
Show Gist options
  • Save samdods/9e6dacbfc10c1794009f984d096315d5 to your computer and use it in GitHub Desktop.
Save samdods/9e6dacbfc10c1794009f984d096315d5 to your computer and use it in GitHub Desktop.
prefix func ~<A>(_ keyPath: KeyPath<A, Bool>) -> (A) -> Bool {
return { $0[keyPath: keyPath] }
}
// only people with empty street in their address
people.filter(~\.address.street.isEmpty)
// the names of the people with empty street
people.filter(~\.address.street.isEmpty).map(~\.name)
// => ["Tom", "Alice", "Bob"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment