Skip to content

Instantly share code, notes, and snippets.

@joshuajhomann
Last active February 24, 2024 05:10
Show Gist options
  • Save joshuajhomann/86793a572337d272b1ad0d22f053e0dc to your computer and use it in GitHub Desktop.
Save joshuajhomann/86793a572337d272b1ad0d22f053e0dc to your computer and use it in GitHub Desktop.
With
@discardableResult public func with<T>(_ item: T, update: (inout T) throws -> Void) rethrows -> T {
var copy = item
try update(&copy)
return copy
}
@inlinable
@discardableResult
public func with<T>( _ value: consuming T, update: (inout T) throws -> Void) rethrows -> T {
var copy = consume value
try update(&copy)
return copy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment