Skip to content

Instantly share code, notes, and snippets.

@jemmons
Created October 6, 2017 23:52
Show Gist options
  • Save jemmons/83a849fcbca5119b43d6b523fc56ec79 to your computer and use it in GitHub Desktop.
Save jemmons/83a849fcbca5119b43d6b523fc56ec79 to your computer and use it in GitHub Desktop.
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")
}
@tinder-garricnahapetian
Copy link

nice!

@Kilo-Loco
Copy link

Kilo-Loco commented Oct 7, 2017

i likey! i would change your struct to just clean it up though

struct Contains { let value: String }

@jemmons
Copy link
Author

jemmons commented Oct 8, 2017

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