Skip to content

Instantly share code, notes, and snippets.

@lilyball
Forked from tel/left-view
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lilyball/924cb802ea57bb17d8b1 to your computer and use it in GitHub Desktop.
Save lilyball/924cb802ea57bb17d8b1 to your computer and use it in GitHub Desktop.
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 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment