Skip to content

Instantly share code, notes, and snippets.

@0xLeif
Created November 29, 2019 18:08
Show Gist options
  • Save 0xLeif/ba25666644ff20255d0a196c4f23de98 to your computer and use it in GitHub Desktop.
Save 0xLeif/ba25666644ff20255d0a196c4f23de98 to your computer and use it in GitHub Desktop.
Optional Use
import Foundation
public extension Optional {
func use(_ closure: (Wrapped) -> Void) {
guard let unwrappedSelf = self else {
return
}
closure(unwrappedSelf)
}
}
var o: String? = nil
o.use {
print($0)
}
o = "534"
o.use {
print($0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment