node-stats-lite icon indicating copy to clipboard operation
node-stats-lite copied to clipboard

Streaming

Open jwerre opened this issue 6 years ago • 1 comments

I'm wondering if there's a way to do this without storing the number array in memory. It would be a nice addition to create a streaming api. Something like:

const stats = require("stats-lite").stream

stat.push(1);
console.log( stats.sum()) // --> 1
stat.push(2);
console.log(stats.sum()) // --> 3
stat.push(3);
console.log(stats.sum()) // --> 6
stat.push(4);
console.log(stats.sum()) // --> 10
stat.push(5);
console.log(stats.sum()) // --> 15

or as a pipe:

const stats = require("stats-lite").stream

readableNumberStream
    .pipe(stats.stdev())

I'm not even sure if that last one is even possible. Can you get the standard deviation without having the entire set of numbers? sum seems pretty straight forward but I'm not sure the other methods could work the same way.

jwerre avatar May 29 '19 20:05 jwerre

Hi @jwerre

Why not simply use rxjs and use the scan or reduce pipe operator?

Odonno avatar Aug 22 '19 17:08 Odonno