<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: 5export const 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>
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
whileLoop: <function (type parameter) A in <A, E, R>(options: {
readonly while: LazyArg<boolean>;
readonly body: LazyArg<Effect<A, E, R>>;
readonly step: (a: A) => void;
}): Effect<void, E, R>
A, function (type parameter) E in <A, E, R>(options: {
readonly while: LazyArg<boolean>;
readonly body: LazyArg<Effect<A, E, R>>;
readonly step: (a: A) => void;
}): Effect<void, E, R>
E, function (type parameter) R in <A, E, R>(options: {
readonly while: LazyArg<boolean>;
readonly body: LazyArg<Effect<A, E, R>>;
readonly step: (a: A) => void;
}): Effect<void, E, R>
R>(options: {
readonly while: LazyArg<boolean>
readonly body: LazyArg<Effect<A, E, R>>
readonly step: (a: A) => void
}
options: {
readonly while: LazyArg<boolean>while: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<boolean>
readonly body: LazyArg<Effect<A, E, R>>body: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <A, E, R>(options: {
readonly while: LazyArg<boolean>;
readonly body: LazyArg<Effect<A, E, R>>;
readonly step: (a: A) => void;
}): Effect<void, E, R>
A, function (type parameter) E in <A, E, R>(options: {
readonly while: LazyArg<boolean>;
readonly body: LazyArg<Effect<A, E, R>>;
readonly step: (a: A) => void;
}): Effect<void, E, R>
E, function (type parameter) R in <A, E, R>(options: {
readonly while: LazyArg<boolean>;
readonly body: LazyArg<Effect<A, E, R>>;
readonly step: (a: A) => void;
}): Effect<void, E, R>
R>>
readonly step: (a: A) => voidstep: (a: Aa: function (type parameter) A in <A, E, R>(options: {
readonly while: LazyArg<boolean>;
readonly body: LazyArg<Effect<A, E, R>>;
readonly step: (a: A) => void;
}): Effect<void, E, R>
A) => void
}) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, function (type parameter) E in <A, E, R>(options: {
readonly while: LazyArg<boolean>;
readonly body: LazyArg<Effect<A, E, R>>;
readonly step: (a: A) => void;
}): Effect<void, E, R>
E, function (type parameter) R in <A, E, R>(options: {
readonly while: LazyArg<boolean>;
readonly body: LazyArg<Effect<A, E, R>>;
readonly step: (a: A) => void;
}): Effect<void, E, R>
R> = import internalinternal.const whileLoop: <A, E, R>(options: {
readonly while: LazyArg<boolean>
readonly body: LazyArg<Effect.Effect<A, E, R>>
readonly step: (a: A) => void
}) => Effect.Effect<void, E, R>
whileLoop