Hyperlinkv0.8.0-beta.28

Effect

Effect.whileLoopconsteffect/Effect.ts:813
<A, E, R>(options: {
  readonly while: LazyArg<boolean>
  readonly body: LazyArg<Effect<A, E, R>>
  readonly step: (a: A) => void
}): Effect<void, E, R>

Executes a body effect repeatedly while a condition holds true.

Example (Repeating an effectful loop)

import { Effect } from "effect"

let counter = 0

const program = Effect.whileLoop({
  while: () => counter < 5,
  body: () => Effect.sync(() => ++counter),
  step: (n) => console.log(`Current count: ${n}`)
})

Effect.runPromise(program)
// Output:
// Current count: 1
// Current count: 2
// Current count: 3
// Current count: 4
// Current count: 5
collecting
Source effect/Effect.ts:8135 lines
export const whileLoop: <A, E, R>(options: {
  readonly while: LazyArg<boolean>
  readonly body: LazyArg<Effect<A, E, R>>
  readonly step: (a: A) => void
}) => Effect<void, E, R> = internal.whileLoop
Referenced by 11 symbols