public
Last active

javascript - sweet.js macro checking for null

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.