Created
August 28, 2017 06:58
-
-
Save uliwitness/053c930eb7a3af5c5e104a7dfdc93a31 to your computer and use it in GitHub Desktop.
Still fascinating how Smalltalk implements if/then/else. Basically it goes like this (in pseudo-Swift):
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
class BooleanClass { | |
void ifTrue(_ trueHandler: () -> Void, else falseHandler: () -> Void) | |
} | |
class TrueBooleanClass { | |
void ifTrue(_ trueHandler: () -> Void, else falseHandler: () -> Void) { | |
trueHandler() | |
} | |
} | |
class FalseBooleanClass { | |
void ifTrue(_ trueHandler: () -> Void, else falseHandler: () -> Void) { | |
falseHandler() | |
} | |
} | |
let True = TrueBooleanClass() | |
let False = FalseBooleanClass() | |
let result: BooleanClass = someFunctionThatReturnsTrueOrFalse() | |
result.ifTrue( { in | |
print("The result was True") | |
}, else: { in | |
print("The result was False") } | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment