Skip to content

Instantly share code, notes, and snippets.

@erikolsson
Created February 13, 2017 11:05
Show Gist options
  • Save erikolsson/d7551922f8649c69a2dc79c1f2bb0817 to your computer and use it in GitHub Desktop.
Save erikolsson/d7551922f8649c69a2dc79c1f2bb0817 to your computer and use it in GitHub Desktop.
// Neat way of avoiding if lets/guard lets
extension Optional {
func then(_ handler:(Wrapped) -> Void) {
switch self {
case .some(let value): handler(value)
case .none: break
}
}
}
var string: String?
string = "hello"
string.then { print($0) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment