jsketcher/modules/lstream/scan.js
2022-06-25 15:19:48 -07:00

19 lines
394 B
JavaScript

import {StreamBase} from './base';
export class ScanStream extends StreamBase {
constructor(stream, seed, scanFunc) {
super();
this.stream = stream;
this.value = seed;
this.scanFunc = scanFunc;
}
attach(observer) {
observer(this.value);
return this.stream.attach(v => {
this.value = this.scanFunc(this.value, v);
observer(this.value);
});
}
}