Create a gist now

Instantly share code, notes, and snippets.

javascript - sweet.js macro checking for null
macro null_helper {
case ($processed ...) ($rest) => {
$processed (.) ... . $rest
}
case ($processed ...) ($rest_head $rest ...) => {
$processed (.) ... . $rest_head
&& null_helper ($processed ... $rest_head) ($rest ...)
}
}
macro nullity {
case ($x) => {
$x
}
case ($head . $rest (.) ...) => {
$head && null_helper ($head) ($rest ...)
}
}
nullity (x.y.z)
// x && x.y && x.y.z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment