3 ms·
var and = require('101/and'); and(true, false); // false and(true, true); // true I'm not convinced that there's a real need for that. Anyone else have a go
by vlunkr 12y ago
var and = require('101/and');
and(true, false); // false
and(true, true); // true
I'm not convinced that there's a real need for that. Anyone else have a good use for something like that? Looks like it doesn't even take more than two arguments
- abelnation 12y agoProviding an function version of `&&` let's you use that function in more FP (functional programming) contexts, e.g. a data transform that does multiple map/apply/reduce transforms to a data set.
- city41 12y agoI'm not convinced either. But for what it's worth, the tests for and() and or() essentially treat them as some() and all() using reduce() https://github.com/tjmehta/101/blob/master/test/test-and.js https://github.com/tjmehta/101/blob/master/test/test-and.js
- noisysocks 12y agoA silly example: var Promise = require('bluebird'); var fs = Promise.promisifyAll(require('fs')); var and = require('101/and'); var paths = [...]; Promise.map(paths, fs.existsAsync).reduce(and) .then(function(allExist) { if (allExist) console.log('all paths exist'); });