Created
April 18, 2022 09:41
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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