stream-intersect

intersections of sorted streams

stream-intersect

intersections of sorted streams

npm install stream-intersect
var cmp = require('typewise-cmp')
function max(ab) { return 0 <= cmp(a, b) ? a : b }
 
function getKey(item) { return item.key }
function maxValue(ab) { return max(a.value, b.value) }
 
var intersect = require('stream-intersect')
    .using({ toKey: getKey, cmp: cmp, merge: maxValue })
 

Intersect two streams.

Customise the behaviour of intersect. Returns a customised intersect function.

the key function is applied to the items before comparison. it defaults to the identity function (a no-op).

a comparison function. return -1 for a < b, 1 for a > b and 0 for a = b. the default comparator considers values equal if they aren't less than or greater than each other.

the merge function is called with every equivalent pair of input items, and its return value is output on the intersection stream. if it returns undefined, nothing will be output. if it returns null, the intersection stream ends.