Last active
May 7, 2016 05:28
-
-
Save willhbr/5069aa475f1cdd5f8b6d36b8e8d5ab2e to your computer and use it in GitHub Desktop.
I hope you're happy
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
/// Please don't do this | |
func iff(condition: Bool, block: () -> ()) -> Bool { | |
if(condition) { | |
block() | |
} | |
return condition | |
} | |
func iff<T>(optional: Optional<T>, block: (val: T) -> ()) -> Bool { | |
if let value = optional { | |
block(val: value) | |
return true | |
} | |
return false | |
} | |
extension Bool { | |
func eelsif(condition: Bool, block: () -> ()) -> Bool { | |
if(!self && condition) { | |
block() | |
} | |
return !self && condition | |
} | |
func eelsif<T>(optional: Optional<T>, block: (val: T) -> ()) -> Bool { | |
guard !self else { return true } | |
if let value = optional { | |
block(val: value) | |
return true | |
} | |
return false | |
} | |
func eels(block: () -> ()) { | |
if(!self) { | |
block() | |
} | |
} | |
} | |
iff(5 > 10) { | |
print("YES") | |
}.eelsif(1 % 2 == 3) { | |
print("Yay") | |
}.eels { | |
print("Nope") | |
} | |
iff(Int("4")) { num in | |
print(num * 4) | |
}.eelsif(Int("6")) { num in | |
print(num + 3) | |
}.eels { | |
print("Hmmm") | |
} | |
false.eels { | |
print("Oh god") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment