Created
June 22, 2017 06:57
-
-
Save rayfix/c887200c45ec29dd34f6a3397e7ce0a6 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
struct BeginsWith { | |
let value: String | |
init(_ value: String) { | |
self.value = value | |
} | |
} | |
func ~=(pattern: BeginsWith, value: String) -> Bool { | |
return value.hasPrefix(pattern.value) | |
} | |
let s = "Hello world" | |
switch s { | |
case BeginsWith("Hello"): | |
print("got it \(s)") | |
case BeginsWith("Goodbye"): | |
print("didn't get it \(s)") | |
default: | |
break | |
} | |
//////////////////////////////////////////////////// | |
func ~=(pattern: String, value: Int) -> Bool { | |
return pattern == String(describing: value) | |
} | |
let x = (1,2,3) | |
switch x { | |
case ("10", "2", _): | |
print("Got it") | |
default: | |
print("Didn't get it") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment