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
  • Select an option

  • Save lilyball/924cb802ea57bb17d8b1 to your computer and use it in GitHub Desktop.

Select an option

Save lilyball/924cb802ea57bb17d8b1 to your computer and use it in GitHub Desktop.

Revisions

  1. lilyball renamed this gist Jul 30, 2014. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions left-view → left-view.swift
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,13 @@
    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], self[advance(startIndex,1)..<endIndex])
    if self.isEmpty {
    return nil
    }
    return (self[startIndex], dropFirst(self))
    }

    var head: Character? { return uncons()?.0 }
    var tail: String? { return uncons()?.1 }
    }
  2. @tel tel revised this gist Jul 30, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion left-view
    Original 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], x[advance(x.startIndex,1)..<x.endIndex])
    case _: return (self[startIndex], self[advance(startIndex,1)..<endIndex])
    }
    }

  3. @tel tel revised this gist Jul 30, 2014. 1 changed file with 7 additions and 10 deletions.
    17 changes: 7 additions & 10 deletions left-view
    Original 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 (head, String())
    case _: return (head, tail)
    case 1: return (self[startIndex], String.empty)
    case _: return (self[startIndex], x[advance(x.startIndex,1)..<x.endIndex])
    }
    }

    var head: Character {
    return Array(self.substringToIndex(advance(self.startIndex, 1)))[0]
    }

    var tail: String {
    return self.substringFromIndex(advance(self.startIndex, 1))
    }
    }
    var head: Character? { return uncons()?.0 }
    var tail: String? { return uncons()?.1 }
    }
  4. @tel tel created this gist Jul 30, 2014.
    17 changes: 17 additions & 0 deletions left-view
    Original 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))
    }
    }