The most basic effect program
import { import Effect
Effect } from "effect";
const const main: Effect.Effect<void, never, never>
main = import Effect
Effect.const sync: <void>(thunk: LazyArg<void>) => Effect.Effect<void, never, never>
Creates an `Effect` that represents a synchronous side-effectful computation.
**Details**
The provided function (`thunk`) must not throw errors; if it does, the error
will be treated as a "defect".
This defect is not a standard error but indicates a flaw in the logic that
was expected to be error-free. You can think of it similar to an unexpected
crash in the program, which can be further managed or logged using tools like
{@link
catchAllDefect
}
.
**When to Use**
Use this function when you are sure the operation will not fail.sync(() => var console: Console
console.Console.log(...data: any[]): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log("Hello World"));
import Effect
Effect.const runSync: <void, never>(effect: Effect.Effect<void, never, never>) => void
Executes an effect synchronously, running it immediately and returning the
result.
**Details**
This function evaluates the provided effect synchronously, returning its
result directly. It is ideal for effects that do not fail or include
asynchronous operations. If the effect does fail or involves async tasks, it
will throw an error. Execution stops at the point of failure or asynchronous
operation, making it unsuitable for effects that require asynchronous
handling.
**Important**: Attempting to run effects that involve asynchronous operations
or failures will result in exceptions being thrown, so use this function with
care for purely synchronous and error-free effects.
**When to Use**
Use this function when:
- You are sure that the effect will not fail or involve asynchronous
operations.
- You need a direct, synchronous result from the effect.
- You are working within a context where asynchronous effects are not
allowed.
Avoid using this function for effects that can fail or require asynchronous
handling. For such cases, consider using
{@link
runPromise
}
or
{@link
runSyncExit
}
.runSync(const main: Effect.Effect<void, never, never>
main);