Skip to content

Instantly share code, notes, and snippets.

@webbower
Created July 15, 2015 21:26
Show Gist options
  • Save webbower/bb7bbc7ef5f3b76d2780 to your computer and use it in GitHub Desktop.
Save webbower/bb7bbc7ef5f3b76d2780 to your computer and use it in GitHub Desktop.
Boolean helper functions
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