Skip to content

eugeneware/mergesort-stream2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 }

About

Merge sorted data from multiple streams into one using streams 2

Resources

License

Stars

Watchers

Forks

Packages

No packages published