Skip to content

Instantly share code, notes, and snippets.

@oconnelltoby
Created December 13, 2020 11:21
Show Gist options
  • Save oconnelltoby/41da3f418942299e0cdcff99042aafaf to your computer and use it in GitHub Desktop.
Save oconnelltoby/41da3f418942299e0cdcff99042aafaf to your computer and use it in GitHub Desktop.
Buildable protocol Swift
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