-
-
Save lilyball/924cb802ea57bb17d8b1 to your computer and use it in GitHub Desktop.
Revisions
-
lilyball renamed this gist
Jul 30, 2014 . 1 changed file with 5 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,13 @@ extension String { static let empty: String = String() func uncons() -> (Character, String)? { if self.isEmpty { return nil } return (self[startIndex], dropFirst(self)) } var head: Character? { return uncons()?.0 } var tail: String? { return uncons()?.1 } } -
tel revised this gist
Jul 30, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ extension String { switch countElements(self) { case 0: return nil case 1: return (self[startIndex], String.empty) case _: return (self[startIndex], self[advance(startIndex,1)..<endIndex]) } } -
tel revised this gist
Jul 30, 2014 . 1 changed file with 7 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,14 @@ extension String { static let empty: String = String() func uncons() -> (Character, String)? { switch countElements(self) { case 0: return nil case 1: return (self[startIndex], String.empty) case _: return (self[startIndex], x[advance(x.startIndex,1)..<x.endIndex]) } } var head: Character? { return uncons()?.0 } var tail: String? { return uncons()?.1 } } -
tel created this gist
Jul 30, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ extension String { func uncons() -> (Character, String)? { switch countElements(self) { case 0: return nil case 1: return (head, String()) case _: return (head, tail) } } var head: Character { return Array(self.substringToIndex(advance(self.startIndex, 1)))[0] } var tail: String { return self.substringFromIndex(advance(self.startIndex, 1)) } }