-
-
Save lilyball/924cb802ea57bb17d8b1 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 { | |
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