Created
October 6, 2017 23:52
-
-
Save jemmons/83a849fcbca5119b43d6b523fc56ec79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Foundation | |
struct Contains { | |
let value: String | |
init(_ str: String) { | |
value = str | |
} | |
} | |
func ~=(pattern: Contains, value: String) -> Bool{ | |
return value.contains(pattern.value) | |
} | |
switch "hello" { | |
case Contains("ll"): | |
print("match") | |
default: | |
print("none") | |
} |
i likey! i would change your struct to just clean it up though
struct Contains { let value: String }
Sure! And YMMV. But if we did that, then we'd have to write case Contains(value: "ll")
which feels too wordy to me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!