sorted-union-stream

WebJar for sorted-union-stream

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

sorted-union-stream
Last Version

Last Version

2.1.3
Release Date

Release Date

Type

Type

jar
Description

Description

sorted-union-stream
WebJar for sorted-union-stream
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/mafintosh/sorted-union-stream

Download sorted-union-stream

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/sorted-union-stream/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>sorted-union-stream</artifactId>
    <version>2.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/sorted-union-stream/
implementation 'org.webjars.npm:sorted-union-stream:2.1.3'
// https://jarcasting.com/artifacts/org.webjars.npm/sorted-union-stream/
implementation ("org.webjars.npm:sorted-union-stream:2.1.3")
'org.webjars.npm:sorted-union-stream:jar:2.1.3'
<dependency org="org.webjars.npm" name="sorted-union-stream" rev="2.1.3">
  <artifact name="sorted-union-stream" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='sorted-union-stream', version='2.1.3')
)
libraryDependencies += "org.webjars.npm" % "sorted-union-stream" % "2.1.3"
[org.webjars.npm/sorted-union-stream "2.1.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : from2 jar [1.3.0,2)
org.webjars.npm : stream-iterate jar [1.1.0,2)

Project Modules

There are no modules declared in this project.

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

Versions

Version
2.1.3