https://github.com/nichoth/pull-combine-latest
Combine the latest values from many pull streams
https://github.com/nichoth/pull-combine-latest
Last synced: over 1 year ago
JSON representation
Combine the latest values from many pull streams
- Host: GitHub
- URL: https://github.com/nichoth/pull-combine-latest
- Owner: nichoth
- Created: 2016-09-11T03:47:29.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-06T01:57:26.000Z (over 9 years ago)
- Last Synced: 2025-03-24T06:22:09.201Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# pull combine latest [](https://travis-ci.org/nichoth/pull-combine-latest)
Combine the latest values from many streams. The algorithm waits until every stream has emitted a value, then emits a new array whenever one of the streams has more data.
## install
$ npm install pull-combine-latest
## example
```js
var S = require('pull-stream')
var combineLatest = require('pull-combine-latest')
S(
// pass an array of streams
combineLatest([S.values([1,2,3]), S.values(['a','b','c'])]),
S.log()
)
S(
// or pass streams as arguments
combineLatest(S.values([1,2,3]), S.values(['a','b','c'])),
S.log()
)
/*
output:
[1,'a']
[2,'a']
[2,'b']
[3,'b']
[3,'c']
*/
// new data is emitted as soon as it is received, so sync data will always
// be emitted before async data
S(
combineLatest(S.values([1,2,3]), asyncValues(['a','b','c'])),
S.log()
)
/*
[1,'a']
[2,'a']
[3,'a']
[3,'b']
[3,'c']
*/
// object map
S(
combineLatest({
a: S.values([1,2,3]),
b: S.values([1,2,3])
}),
S.log()
)
/*
{ a: 1, b: 1 }
{ a: 2, b: 1 }
{ a: 2, b: 2 }
{ a: 3, b: 2 }
{ a: 3, b: 3 }
*/
```