Created
December 13, 2020 11:21
-
-
Save oconnelltoby/41da3f418942299e0cdcff99042aafaf to your computer and use it in GitHub Desktop.
Buildable protocol 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 with(transform: (inout Self) throws -> Void) rethrows -> Self { | |
var mutableSelf = self | |
try transform(&mutableSelf) | |
return mutableSelf | |
} | |
} | |
func mutating<Type>(_ type: Type, transform: (inout Type) throws -> Void) rethrows -> Type { | |
var mutableType = type | |
try transform(&mutableType) | |
return mutableType | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment