Last active
August 24, 2021 08:15
-
-
Save avdyushin/6b0bf5e113bf91791d65c7a8d6915ab5 to your computer and use it in GitHub Desktop.
Swift 4 hasPrefix in switch
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
let string = "www." | |
func hasPrefix(_ prefix: String) -> (String) -> Bool { | |
return { value in value.hasPrefix(prefix) } | |
} | |
func ~=(block: (String) -> Bool, string: String) -> Bool { | |
return block(string) | |
} | |
switch string { | |
case hasPrefix("www"): | |
debugPrint("Has www") | |
default: | |
() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment