@basic-streams/scan
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@basic-streams/scan

scan<N, A>(
  reducer: (accumulated: A, next: N) => A,
  seed: A,
  stream: Stream<N>,
): Stream<A>

Creates a stream containing reducer(a, x) for each value x from the source stream, and the latest value a produced from by the resulting stream. The resulting stream will also have given seed as the first event.

import ofMany from "@basic-streams/of-many"
import scan from "@basic-streams/scan"

const stream = ofMany([1, 2, 3], 5000)

const result = scan((acc, next) => acc + next, 0, stream)

result(x => {
  console.log(x)
})

// > 0
// > 1
// > 3
// > 6

// stream: ____1____2____3
// result: 0___1____3____6

Readme

Keywords

Package Sidebar

Install

npm i @basic-streams/scan

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

4.04 kB

Total Files

8

Last publish

Collaborators

  • pozadi