Skip to content

Instantly share code, notes, and snippets.

@hoshi-takanori
Created August 18, 2016 02:12
Show Gist options
  • Save hoshi-takanori/99133d3f8161401ca054b9f4cdf55673 to your computer and use it in GitHub Desktop.
Save hoshi-takanori/99133d3f8161401ca054b9f4cdf55673 to your computer and use it in GitHub Desktop.
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