Skip to content

Instantly share code, notes, and snippets.

@Idorobots
Last active January 1, 2016 15:19
Show Gist options
  • Save Idorobots/8163848 to your computer and use it in GitHub Desktop.
Save Idorobots/8163848 to your computer and use it in GitHub Desktop.
Why OOP when you can NOOP?
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