mergesort-stream2

1.3.0 • Public • Published

mergesort-stream2

Merge sorted data from multiple streams into one using streams 2

build status

Essentially a streams 2 implementation of the excellent mergesort-stream

Installation

This module is installed via npm:

$ npm install mergesort-stream2

Example Usage

var mergesort= require('mergesort-stream2'),
    through2 = require('through2');
 
// stream that will output the object stream ({num: 42}, {num: 44}, {num: 58})
var s1 = testStream([42, 44, 58]);
 
// stream that will output the object stream ({num: 40}, {num: 41}, {num: 52})
var s2 = testStream([40, 41, 52]);
 
// custom comparator function to help sort the objects
function cmp(a, b) {
  // sort by the 'num' field
  var _a = a.num;
  var _b = b.num;
 
  if (_a < _b) return -1;
  if (_a > _b) return +1;
  return 0;
}
 
mergesort(cmp, [s1, s2])
  .pipe(through2(function (data, enc, cb) {
    console.log(data);
    cb();
  }));
 
// Will output:
// { num: 40 }
// { num: 41 }
// { num: 42 }
// { num: 44 }
// { num: 52 }
// { num: 58 }

Package Sidebar

Install

npm i mergesort-stream2

Weekly Downloads

6

Version

1.3.0

License

BSD-3-Clause

Last publish

Collaborators

  • eugeneware