https://github.com/nichoth/pull-scan
Scan algorithm for pull streams
https://github.com/nichoth/pull-scan
Last synced: about 1 month ago
JSON representation
Scan algorithm for pull streams
- Host: GitHub
- URL: https://github.com/nichoth/pull-scan
- Owner: nichoth
- Created: 2016-09-29T00:18:37.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-29T16:33:45.000Z (almost 10 years ago)
- Last Synced: 2025-08-09T13:42:08.079Z (12 months ago)
- Language: JavaScript
- Homepage: https://github.com/nichoth/pull-scan#readme
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## pull scan [](https://travis-ci.org/nichoth/pull-scan)
[Scan algorithm](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/scan.md) for pull streams. It's like reduce, but emits intermediate values. So it's more like map but with an accumulator argument.
## example
```js
var test = require('tape')
var S = require('pull-stream')
var scan = require('../')
test('works given initial state', function (t) {
t.plan(1)
S(
S.values([1,2,3]),
scan(function (acc, n) {
return acc + n
}, 10),
S.collect(function (err, data) {
t.deepEqual(data, [11,13,16], 'should use init state argument')
})
)
})
test('use default init state', function (t) {
t.plan(1)
S(
S.values([1,2,3]),
scan(function (acc, n) {
return acc + n
}),
S.collect(function (err, data) {
t.deepEqual(data, [1,3,6],
'should use first val as default state')
})
)
})
```