-
-
Save beccadax/e2dc0672b0617b4a1e64 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
extension String { | |
func split(separator:String) -> [String] { | |
return self.componentsSeparatedByString(separator) | |
} | |
} | |
extension Array { | |
func unpack() -> (T)? { | |
return count == 1 ? (self[0]) : nil | |
} | |
func unpack() -> (T, T)? { | |
return count == 2 ? (self[0], self[1]) : nil | |
} | |
func unpack() -> (T, T, T)? { | |
return count == 3 ? (self[0], self[1], self[2]) : nil | |
} | |
func unpack() -> (T, T, T, T)? { | |
return count == 4 ? (self[0], self[1], self[2], self[3]) : nil | |
} | |
func unpack() -> (T, T, T, T, T)? { | |
return count == 5 ? (self[0], self[1], self[2], self[3], self[4]) : nil | |
} | |
func unpack() -> (T, T, T, T, T, T)? { | |
return count == 6 ? (self[0], self[1], self[2], self[3], self[4], self[5]) : nil | |
} | |
func unpack() -> (T, T, T, T, T, T, T)? { | |
return count == 7 ? (self[0], self[1], self[2], self[3], self[4], self[5], self[6]) : nil | |
} | |
func unpack() -> (T, T, T, T, T, T, T, T)? { | |
return count == 8 ? (self[0], self[1], self[2], self[3], self[4], self[5], self[6], self[7]) : nil | |
} | |
func unpack() -> (T, T, T, T, T, T, T, T, T)? { | |
return count == 9 ? (self[0], self[1], self[2], self[3], self[4], self[5], self[6], self[7], self[8]) : nil | |
} | |
func unpack() -> (T, T, T, T, T, T, T, T, T, T)? { | |
return count == 10 ? (self[0], self[1], self[2], self[3], self[4], self[5], self[6], self[7], self[8], self[9]) : nil | |
} | |
} | |
if let (hello, world) = "Hello, world".split(", ").unpack() { | |
println(hello) | |
println(world) | |
} | |
if let (hello, world) = "Hello, world, omg".split(", ").unpack() { | |
println(hello) | |
println(world) | |
} | |
if let (first, last, birthday) = "Bob, Quone, January 1st 1987".split(", ").unpack() { | |
println(first) | |
println(last) | |
println(birthday) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment