Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cond macro
macro _arms {
case (default => $value:expr) => {
else {
return $value;
}
}
case (case $cond:expr => $value:expr) => {
if($cond) {
return $value;
}
}
case (
$(case $cond:expr => $value:expr) $rest ...
) => {
_arms (case $cond => $value)
_arms ($rest ...)
}
}
macro cond {
case { $arms ... } => {
(function() {
_arms($arms ...)
})();
}
}
var x = [];
var type = cond {
case (x === null) => "null"
case Array.isArray(x) => "array"
case (typeof x === "object") => "object"
default => typeof x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.