Skip to content

Instantly share code, notes, and snippets.

@k0nserv
Created August 19, 2014 20:35
Show Gist options
  • Save k0nserv/633bcc3ea2ff0ee4bc2d to your computer and use it in GitHub Desktop.
Save k0nserv/633bcc3ea2ff0ee4bc2d to your computer and use it in GitHub Desktop.
// Define the ++= operator
infix operator ++= {}
func ++= (action: @autoclosure () -> (), condition: BooleanType){
unless(condition, action)
}
var x = 1
// This is equal to ruby's
// x = 2 unless 1 > 2
(x = 2) ++= 1 > 2
println("\(x)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment