Created
June 21, 2019 03:13
-
-
Save omochi/b0fe2aed5465057bde9061da1b200768 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
extension Optional { | |
public mutating func ensure(_ f: () throws -> Wrapped) rethrows -> Wrapped { | |
if let x = self { | |
return x | |
} | |
let x = try f() | |
self = x | |
return x | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment