Skip to content

Instantly share code, notes, and snippets.

@mikeash
Created July 13, 2018 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeash/e8d0f09cdc2b1c041db1451fbeb18d3f to your computer and use it in GitHub Desktop.
Save mikeash/e8d0f09cdc2b1c041db1451fbeb18d3f to your computer and use it in GitHub Desktop.
func effIt<Target, Result>(_ keypath: KeyPath<Target, Result>) -> (Target) -> Result {
return { $0[keyPath: keypath] }
}
struct Foo {
var x: Int
var y: Int
}
let f = effIt(\Foo.x)
let foo = Foo(x: 42, y: 43)
print(f(foo))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment