Skip to content

Instantly share code, notes, and snippets.

@jasdev
Created July 20, 2020 01:27
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 jasdev/31c50e00016aa03866adafd501708bde to your computer and use it in GitHub Desktop.
Save jasdev/31c50e00016aa03866adafd501708bde to your computer and use it in GitHub Desktop.
Deriving a setter from a key path.
func setterFromKeyPath<Value, Subject>(
_ keyPath: WritableKeyPath<Value, Subject>
) -> (inout Value, Subject) -> Void {
{ value, subject in value[keyPath: keyPath] = subject }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment