Created
August 18, 2016 02:12
-
-
Save hoshi-takanori/99133d3f8161401ca054b9f4cdf55673 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
extension Optional { | |
func isNilOr(block: Wrapped -> Bool) -> Bool { | |
switch self { | |
case .None: | |
return true | |
case .Some(let value): | |
return block(value) | |
} | |
} | |
} | |
var str: String? = nil | |
str.isNilOr { $0.isEmpty } // $R0: Bool = true | |
str = "" | |
str.isNilOr { $0.isEmpty } // $R1: Bool = true | |
str = "a" | |
str.isNilOr { $0.isEmpty } // $R2: Bool = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment