Created
February 13, 2017 11:05
-
-
Save erikolsson/d7551922f8649c69a2dc79c1f2bb0817 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
// 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