Skip to content

Instantly share code, notes, and snippets.

@0ex-d
Created October 10, 2022 21:27
Show Gist options
  • Save 0ex-d/acb3ba2ea9fc60223850998f8f6183b4 to your computer and use it in GitHub Desktop.
Save 0ex-d/acb3ba2ea9fc60223850998f8f6183b4 to your computer and use it in GitHub Desktop.
🥹 My top Longest Short-Circuit Evaluation in Javascript and Rust.
// use good 'ol c-language one-liner (rust doesn't have terniary operator 🙂)
let x = if true { if false { true } else { false } } else { if true { false } else { true } };
// could also be
let x = if true { !false } else { !true };
// even further
let x = if true { true } else { false };
// quick short-circuit
let x = if (true) {
if (false) { true } else { false }
} else {
if (true) { false } else { true }
};
// exhaustive matching (or None)
match (a, b) {
(true, true) => ...,
(true, false) => ...,
(false, true) => ...,
(false, false) => ...,
_ => ...
}
// Javascript has terniary operator, could be good or could also get out of hand
let x = true ? false ? true : false : true ? false : true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment