Skip to content

Instantly share code, notes, and snippets.

@erica
Last active April 20, 2016 21:57
Show Gist options
  • Select an option

  • Save erica/5afb13c72ec372a09042bb29dbbd77a3 to your computer and use it in GitHub Desktop.

Select an option

Save erica/5afb13c72ec372a09042bb29dbbd77a3 to your computer and use it in GitHub Desktop.

Revisions

  1. erica revised this gist Apr 20, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions nostalgia.swift
    Original file line number Diff line number Diff line change
    @@ -40,8 +40,8 @@ prefix operator +++ {}
    prefix public func +++<T: IntegerArithmeticType>(inout x: T) -> T { x += x/x; return x }

    // CGFloat versions apparently need separate implementations
    //prefix public func +++<T: IntegerArithmeticType>(inout x: CGFloat) -> CGFloat { defer { x += 1 }; return x }
    //prefix public func +++<T: IntegerArithmeticType>(inout x: CGFloat) -> CGFloat { x += 1; return x }
    //prefix public func +++(inout x: CGFloat) -> CGFloat { defer { x += 1 }; return x }
    //prefix public func +++(inout x: CGFloat) -> CGFloat { x += 1; return x }

    // via "torquato"

  2. erica revised this gist Apr 20, 2016. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions nostalgia.swift
    Original file line number Diff line number Diff line change
    @@ -43,3 +43,14 @@ prefix public func +++<T: IntegerArithmeticType>(inout x: T) -> T { x += x/x; re
    //prefix public func +++<T: IntegerArithmeticType>(inout x: CGFloat) -> CGFloat { defer { x += 1 }; return x }
    //prefix public func +++<T: IntegerArithmeticType>(inout x: CGFloat) -> CGFloat { x += 1; return x }

    // via "torquato"

    postfix operator ++++ {}
    postfix public func ++++<T: BidirectionalIndexType>(inout x: T) -> T { defer { x = x.successor() }; return x }
    prefix operator ++++ {}
    prefix public func ++++<T: BidirectionalIndexType>(inout x: T) -> T { x = x.successor(); return x }
    postfix operator ---- {}
    postfix public func ----<T: BidirectionalIndexType>(inout x: T) -> T { defer { x = x.predecessor() }; return x }
    prefix operator ---- {}
    prefix public func ----<T: BidirectionalIndexType>(inout x: T) -> T { x = x.predecessor(); return x }

  3. erica revised this gist Apr 20, 2016. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions nostalgia.swift
    Original file line number Diff line number Diff line change
    @@ -30,3 +30,16 @@ postfix operator -- {}
    postfix public func --(inout x: Int) -> Int { defer {x -= 1}; return x }
    // @discardableResult
    postfix public func --(inout x: UInt) -> UInt { defer {x -= 1}; return x }

    // Alternatively, deriving 1
    // via Pilipenko Dima http://github.com/dimpiax
    postfix operator +++ {}
    postfix public func +++<T: IntegerArithmeticType>(inout x: T) -> T { defer { x += x/x }; return x }

    prefix operator +++ {}
    prefix public func +++<T: IntegerArithmeticType>(inout x: T) -> T { x += x/x; return x }

    // CGFloat versions apparently need separate implementations
    //prefix public func +++<T: IntegerArithmeticType>(inout x: CGFloat) -> CGFloat { defer { x += 1 }; return x }
    //prefix public func +++<T: IntegerArithmeticType>(inout x: CGFloat) -> CGFloat { x += 1; return x }

  4. erica revised this gist Apr 20, 2016. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions nostalgia.swift
    Original file line number Diff line number Diff line change
    @@ -17,3 +17,16 @@ postfix operator ++ {}
    postfix public func ++(inout x: Int) -> Int { defer {x += 1}; return x }
    // @discardableResult
    postfix public func ++(inout x: UInt) -> UInt { defer {x += 1}; return x }

    prefix operator -- {}
    // @discardableResult
    prefix public func --(inout x: Int) -> Int { x -= 1; return x }
    // @discardableResult
    prefix public func --(inout x: UInt) -> UInt { x -= 1; return x }


    postfix operator -- {}
    // @discardableResult
    postfix public func --(inout x: Int) -> Int { defer {x -= 1}; return x }
    // @discardableResult
    postfix public func --(inout x: UInt) -> UInt { defer {x -= 1}; return x }
  5. erica revised this gist Apr 20, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions nostalgia.swift
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,9 @@

    prefix operator ++ {}
    // @discardableResult
    prefix public func ++(inout x: Int) -> Int { x = x + 1; return x }
    prefix public func ++(inout x: Int) -> Int { x += 1; return x }
    // @discardableResult
    prefix public func ++(inout x: UInt) -> UInt { x = x + 1; return x }
    prefix public func ++(inout x: UInt) -> UInt { x += 1; return x }


    postfix operator ++ {}
  6. erica revised this gist Apr 20, 2016. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions nostalgia.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    /*

    ericasadun.com
    Sometimes letting go doesn't mean saying goodbye

    */

    prefix operator ++ {}
    // @discardableResult
    prefix public func ++(inout x: Int) -> Int { x = x + 1; return x }
  7. erica revised this gist Apr 20, 2016. 1 changed file with 2 additions and 9 deletions.
    11 changes: 2 additions & 9 deletions nostalgia.swift
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,3 @@
    /*

    ericasadun.com
    Sometimes letting go doesn't mean saying goodbye

    */

    prefix operator ++ {}
    // @discardableResult
    prefix public func ++(inout x: Int) -> Int { x = x + 1; return x }
    @@ -14,6 +7,6 @@ prefix public func ++(inout x: UInt) -> UInt { x = x + 1; return x }

    postfix operator ++ {}
    // @discardableResult
    postfix public func ++(inout x: Int) -> Int { x = x + 1; return x - 1 }
    postfix public func ++(inout x: Int) -> Int { defer {x += 1}; return x }
    // @discardableResult
    postfix public func ++(inout x: UInt) -> UInt { x = x + 1; return x - 1 }
    postfix public func ++(inout x: UInt) -> UInt { defer {x += 1}; return x }
  8. erica created this gist Apr 19, 2016.
    19 changes: 19 additions & 0 deletions nostalgia.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    /*

    ericasadun.com
    Sometimes letting go doesn't mean saying goodbye

    */

    prefix operator ++ {}
    // @discardableResult
    prefix public func ++(inout x: Int) -> Int { x = x + 1; return x }
    // @discardableResult
    prefix public func ++(inout x: UInt) -> UInt { x = x + 1; return x }


    postfix operator ++ {}
    // @discardableResult
    postfix public func ++(inout x: Int) -> Int { x = x + 1; return x - 1 }
    // @discardableResult
    postfix public func ++(inout x: UInt) -> UInt { x = x + 1; return x - 1 }