Skip to content

Instantly share code, notes, and snippets.

@andreivasilache
Created April 18, 2022 09:41
Show Gist options
  • Save andreivasilache/3b29f6f59a40cb9200ab631e99ac9719 to your computer and use it in GitHub Desktop.
Save andreivasilache/3b29f6f59a40cb9200ab631e99ac9719 to your computer and use it in GitHub Desktop.
Utility used in order to avoid ugly nested ternary statements. (Idea: https://medium.com/fractions/3-more-marvelous-javascript-tips-to-skyrocket-your-productivity-ba75f72b0195)
const is = (val) => ({
if: (expr) => {
if (expr)
return {
else: () => val,
is: function is() {
return {
if: () => ({ else: () => val, is }),
}
},
}
else return { else: (e) => e, is }
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment