Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sorted-union-stream

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sorted-union-stream

Get the union of two sorted streams

  • 3.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
126K
increased by8.86%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 09 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc