Skip to content

Instantly share code, notes, and snippets.

@lilyball
Forked from erica/gist:0342d7d1ee347774c990
Last active August 29, 2015 14:11
Show Gist options
  • Save lilyball/d6d0444f9838052f1a08 to your computer and use it in GitHub Desktop.
Save lilyball/d6d0444f9838052f1a08 to your computer and use it in GitHub Desktop.
extension Optional {
func and<U>(x:U?) -> (T, U)? {
switch (self, x) {
case let (.Some(a), .Some(b)):
return (a, b)
default:
return nil
}
}
}
var x : Int?
var y : Int?
x = 5
y = 60
if let (a, b) = x.and(y) {
println("\(a), \(b)")
} else {
println("nope")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment