I’m writing a tool which processes a bunch of text passed in to `stdin`, each line is an “entry”. I’d like to make my code more functional, so I’d like to treat the set of lines as a “sequence” or “iterable” and iterate over it using `reduce`.

I’m currently using the [Node](http://nodejs.org/) module [LineStream](https://github.com/shinout/LineStream) to process `stdin` as a set of lines, but it works by dispatching a `data` event for each line — which is fine, it’s implementing the [Readable Stream](http://nodejs.org/docs/latest/api/streams.html#readable_Stream) interface.

So I’m currently doing kind of a very “manual” reduce by passing the interim value in to my function every time the `data` event fires:

```
var windows = [];

linestream.on('data', function(line) {
  return windows = rollup(windows, extractDate(line), argv.w);
});

linestream.on('end', function() {
  return process.stdout.write(toCsv(windows));
});

process.stdin.resume();

```

But it’d be more functional to do something like:

```
linestream.lines.reduce(rollup, []);

function rollup(windows, line) {
    // would return a new interim or final value
}

```

Of course, I could “collect” all the lines into a regular array and then reduce it, but I tried that and it uses way too much memory when I’m running my tool on a large dataset — so something like iteration over the stream is really what’s necessary.

I guess what I’m asking is whether it’s possible to write a Node function/module which would do this, or whether one exists already.

Thanks!