effect-io-ai

Package: effect
Module: Stream

Stream.iterate

Creates an infinite stream by repeatedly applying a function to a seed value.

Example (Iterating from a seed value)

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

const stream = Stream.iterate(1, (n) => n + 1).pipe(Stream.take(3))

const program = Effect.gen(function* () {
  const values = yield* Stream.runCollect(stream)
  yield* Console.log(values)
})

Effect.runPromise(program)
// Output: [ 1, 2, 3 ]

Signature

declare const iterate: <A>(value: A, next: (value: A) => A) => Stream<A>

Source

Since v2.0.0