Hyperlinkv0.8.0-beta.28

Stream

Stream.iterateconsteffect/Stream.ts:1729
<A>(value: A, next: (value: A) => A): Stream<A>

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 ]
constructors
Source effect/Stream.ts:17292 lines
export const iterate = <A>(value: A, next: (value: A) => A): Stream<A> =>
  unfold(value, (a) => Effect.succeed([a, next(a)]))