effect-io-ai

Package: effect
Module: Stream

Stream.debounce

Drops earlier elements within the debounce window and emits only the latest element after the pause.

Example (Debouncing stream elements)

import { Console, Duration, Effect, Stream } from "effect"

const stream = Stream.make(1, 2, 3).pipe(
  Stream.concat(Stream.fromEffect(Effect.sleep(Duration.millis(50)).pipe(Effect.as(4)))),
  Stream.concat(Stream.make(5)),
  Stream.debounce(Duration.millis(30))
)

const program = Effect.gen(function*() {
  const values = yield* Stream.runCollect(stream)
  yield* Console.log(values)
  // Output: [ 3, 5 ]
})

Signature

declare const debounce: { (duration: Duration.Input): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R>; <A, E, R>(self: Stream<A, E, R>, duration: Duration.Input): Stream<A, E, R>; }

Source

Since v2.0.0