-
-
Save piotrtobolski/6c964de93390fc508b9e75c974f19a1b to your computer and use it in GitHub Desktop.
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
@discardableResult | |
@inlinable | |
private func with<T>(_ value: T, _ builder: (T) throws -> Void) rethrows -> T { | |
try builder(value) | |
return value | |
} | |
// Use | |
class MyClass { | |
var prop = "it's" | |
init() {} | |
} | |
let instance = with(MyClass()) { | |
$0.prop += " awesome" | |
} | |
print(instance.prop) //"it's awesome" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment