Skip to content

Instantly share code, notes, and snippets.

@regnerjr
Created June 28, 2015 22:48
Show Gist options
  • Select an option

  • Save regnerjr/c81814daabf8097ab07c to your computer and use it in GitHub Desktop.

Select an option

Save regnerjr/c81814daabf8097ab07c to your computer and use it in GitHub Desktop.
Method chaining and reducing if statements
extension BooleanLiteralType {
func if_true(block: () -> () ) -> BooleanLiteralType{
if self {
block()
}
return self
}
func if_false(block: () -> ()) -> BooleanLiteralType {
if !self {
block()
}
return self
}
}
(1 == 1).if_false{print("Help I'm False")}
.if_true{print("Awesome, I'm True")}
(1 == 2).if_true{print("Help I'm True")}
.if_false{print("Sweet, I'm False")}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment