Created
July 13, 2022 18:23
-
-
Save V8tr/4eae6dcbf43471598ddad83572da3d7e to your computer and use it in GitHub Desktop.
KeyPath-based builder in Swift
This file contains 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
protocol Buildable {} | |
extension Buildable { | |
func set<T>(_ keyPath: WritableKeyPath<Self, T>, to newValue: T) -> Self { | |
var copy = self | |
copy[keyPath: keyPath] = newValue | |
return copy | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment