Created
June 14, 2014 22:36
-
-
Save nickmain/9a7a28f77c8c780876aa to your computer and use it in GitHub Desktop.
Using pattern matching on tuples of Optionals
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
// Playground - noun: a place where people can play | |
import Cocoa | |
func checkOptionals(a:Dictionary<String,Int>,key1:String,key2:String) { | |
switch (a[key1],a[key2]) { | |
case (.Some(_),.Some(_)): println("both") | |
case (.Some(let a),.None): println("first " + String(a)) | |
case (.None,.Some(let b)): println("second " + String(b)) | |
default: println("neither") | |
} | |
} | |
let dict = ["x":5,"y":6,"z":7] | |
checkOptionals(dict,"g","h") | |
checkOptionals(dict,"x","g") | |
checkOptionals(dict,"h","y") | |
checkOptionals(dict,"x","z") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Console output is: