Created
July 15, 2015 21:26
-
-
Save webbower/bb7bbc7ef5f3b76d2780 to your computer and use it in GitHub Desktop.
Boolean helper functions
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
function existy(value) { | |
return value !== undefined && value !== null; | |
} | |
function falsey(value) { | |
return !existy(value) || value === false; | |
} | |
function truthy(value) { | |
return !falsey(value); | |
} | |
function result(value) { | |
return typeof value === 'function' ? value() : value; | |
} | |
function and() { | |
var tests = toArray(arguments); | |
if(tests[0]) return and.apply(null, rest(tests)); | |
else return false; | |
} | |
function or() { | |
var tests = toArray(arguments); | |
if(tests[0]) return true; | |
else return or.apply(null, rest(tests)); | |
} | |
function ite(iff, thn, els) { | |
if(result(iff)) return result(thn); | |
else return result(els); | |
} | |
function unless(els, then) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment