sorted-union-stream

Get the union of two sorted streams

MIT 22 个版本
安装
npm install sorted-union-stream
yarn add sorted-union-stream
pnpm add sorted-union-stream
bun add sorted-union-stream
README

sorted-union-stream

Get the union of two sorted streams

npm install sorted-union-stream

build status

Usage

const union = require('sorted-union-stream')
const { Readable } = require('streamx')

// from converts an array into a stream
const sorted1 = Readable.from([1, 10, 24, 42, 43, 50, 55])
const sorted2 = Readable.from([10, 42, 53, 55, 60])

// combine the two streams into a single sorted stream
const u = new Union(sorted1, sorted2)

u.on('data', function(data) {
  console.log(data)
})
u.on('end', function() {
  console.log('no more data')
})

Running the above example will print

1
10
24
42
43
50
53
55
60
no more data

Streaming objects

If you are streaming objects sorting is based on the compare function you can pass as the 3rd argument.

const sorted1 = Readable.from([{ foo:'a' }, { foo:'b' }, { foo:'c' }])
const sorted2 = Readable.from([{ foo:'b' }, { foo:'d' }])

const u = new Union(sorted1, sorted2, function(a, b) {
  return a.foo < b.foo ? -1 : a.foo > b.foo ? 1 : 0 
})

union.on('data', function(data) {
  console.log(data)
})

Running the above will print

{ foo: 'a' }
{ foo: 'b' }
{ foo: 'c' }
{ foo: 'd' }

License

MIT

版本列表
3.2.3 2023-03-09
3.2.2 2023-03-02
3.2.1 2023-03-02
3.2.0 2023-03-02
3.1.0 2021-09-01
3.0.1 2020-01-15
3.0.0 2020-01-15
2.1.3 2015-06-16
2.1.2 2015-06-16
2.1.1 2015-04-08
2.1.0 2015-04-08
2.0.0 2015-04-02
1.0.2 2014-12-22
1.0.1 2014-09-18
1.0.0 2014-09-18
0.2.5 2013-09-20
0.2.4 2013-09-20
0.2.3 2013-09-15
0.2.2 2013-09-15
0.2.1 2013-09-11
0.2.0 2013-09-11
0.1.0 2013-09-11