Created
July 13, 2018 21:03
-
-
Save mikeash/e8d0f09cdc2b1c041db1451fbeb18d3f to your computer and use it in GitHub Desktop.
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 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