Last active
January 1, 2016 15:19
-
-
Save Idorobots/8163848 to your computer and use it in GitHub Desktop.
Why OOP when you can NOOP?
This file contains hidden or 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
private auto typeDispatch(T, Cs...)(T value, Cs callbacks) { | |
/*static*/ foreach(i, C; Cs) { | |
if((cast(ParameterTypeTuple!C[0]) value) !is null) { | |
return callbacks[i](cast(ParameterTypeTuple!C[0]) value); | |
} | |
} | |
throw new SemanticError("Can't compile that!"); | |
} | |
// ... | |
return typeDispatch( | |
e, | |
(Variable var) { | |
// Do stuff with var... | |
}, | |
(Application app) { | |
// Do stuff with app... | |
}, | |
(Expression expr) { | |
// Do stuff with expr... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment