Created
April 1, 2020 05:07
-
-
Save nverinaud/a31624a05924b623224fb686fd7bfde3 to your computer and use it in GitHub Desktop.
Swift Kotlinified : Optional.let
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 { | |
func `let`(_ action: (Wrapped) -> ()) { | |
if let value = self { | |
action(value) | |
} | |
} | |
} | |
// Usage | |
func stopObserving(_ observer: Any?) { | |
observer.let(notificationCenter.removeObserver) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment