Dev Helpers
← Back

Count a stream with reduce

Count a stream with reduce using Node.js.

Open this example in the interactive library

Source code

import {
  Readable,
  Writable,
  Transform,
  PassThrough,
  isReadable,
  isWritable,
} from "node:stream";
import { text, json, arrayBuffer } from "node:stream/consumers";
import { pipeline, finished } from "node:stream/promises";
console.log(await Readable.from([2, 3, 4]).reduce((sum, n) => sum + n, 0));

Sample output

9