it ('should drop the put if transducer filters it out', (cb) => { var ch = chan(null, t.filter((n) => n > 1)) take(ch) .then((val) => assert(val === 2)) .then(cb) put(ch, 1) // dropped put(ch, 2) })
it('should allow filtering', function() { var a = [1, 2, 3]; var s = transduce(t.filter(even), fromArray(a)); return reduce(function(results, x) { return results.concat(x); }, [], s) .then(function(results) { expect(results).toEqual(a.filter(even)); }); });
.range(1, 1000000) .selectMany(function(x) { return randObs() }) function toPercent(x) { return Math.floor(x * 100); } function isEven(x) { return x % 2 === 0; } function sum(x, y) { return x + y } let transducer = t.comp(t.map(toPercent), t.filter(isEven)); // Native higher-order function console.time("native higher-order function"); source .map(toPercent) .filter(isEven) .reduce(sum) console.timeEnd("native higher-order function"); // Transducers console.time("transducers"); t.transduce(transducer, sum, 0, source);