Skip to content

Instantly share code, notes, and snippets.

@Qata
Created July 25, 2017 05:46
Show Gist options
  • Save Qata/992a66b224e583ffea8bf65ffbcb9b87 to your computer and use it in GitHub Desktop.
Save Qata/992a66b224e583ffea8bf65ffbcb9b87 to your computer and use it in GitHub Desktop.
enum Plain {}
enum Encoded {}
enum Decompressed {}
enum Compressed {}
struct Bytes<A, B> {
let string: String
}
extension Bytes where A == Plain, B == Decompressed {
func encode() -> Bytes<Encoded, Decompressed> {
return Bytes<Encoded, Decompressed>(string: string.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? "")
}
}
extension Bytes where A == Encoded, B == Decompressed {
func encode() -> Bytes<Plain, Decompressed> {
return Bytes<Plain, Decompressed>(string: string.removingPercentEncoding ?? "")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment