rxjs-transducer
A transducer implementation using the excellent and well known operators from RxJS. The benefits are:
- Performance: Doing a array.map().filter().reduce() causes the array to be iterated 3 times. Using rxjs-transducers, the array is only iterated once. Doing a
filter().map().Math.max()
on an array with 1,000,000 items is roughly three times as fast with the transducer as with normal array operations. - Ability to work with lazy and infinite collections (generators)
- Access to a huge library of well tested operators from RxJS such as
map
,filter
,reduce
,skip
,take
,takeWhile
, and many others - Full TypeScript support
Installation
npm install rxjs-transducer --save
Usage
TypeScript / ES6
;;; // Works as standard array map and filter, but faster (only one iteration);// result -> ['ABC', 'ABCD', 'ABCDE'] // Note that results is always an array, even if the final operator// only produces a single result;// result -> ['ABC-ABCD-ABCDE'] // Works with infinte sequences too;// result -> [100, 110, 120, 130, 140] // Infinite sequence of integers from zero -> infinite
Javascript
const map filter reduce take skip = ;const transducer = ;const source = 'a' 'ab' 'abc' 'abcd' 'abcde'; const result = ;// result -> ['ABC', 'ABCD', 'ABCDE']
Test
npm run test