(seed: string | number): <A, E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
<A, E, R>(
self: Effect.Effect<A, E, R>,
seed: string | number
): Effect.Effect<A, E, R>Seeds the pseudo-random number generator with the specified value.
When to use
Use to run an effect with a deterministic pseudo-random sequence.
Details
Using the same seed produces the same random sequence, which is useful for tests and reproducible simulations.
Gotchas
Use an unpredictable seed when uniqueness or unpredictability matters.
Example (Seeding random generation)
import { Effect, Random } from "effect"
const program = Effect.gen(function*() {
const value1 = yield* Random.next
const value2 = yield* Random.next
console.log(value1, value2)
})
// Same seed produces same sequence
const seeded1 = program.pipe(Random.withSeed("my-seed"))
const seeded2 = program.pipe(Random.withSeed("my-seed"))
// Both will output identical values
Effect.runPromise(seeded1)
Effect.runPromise(seeded2)export const const withSeed: {
(seed: string | number): <A, E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
<A, E, R>(
self: Effect.Effect<A, E, R>,
seed: string | number
): Effect.Effect<A, E, R>
}
Seeds the pseudo-random number generator with the specified value.
When to use
Use to run an effect with a deterministic pseudo-random sequence.
Details
Using the same seed produces the same random sequence, which is useful for
tests and reproducible simulations.
Gotchas
Use an unpredictable seed when uniqueness or unpredictability matters.
Example (Seeding random generation)
import { Effect, Random } from "effect"
const program = Effect.gen(function*() {
const value1 = yield* Random.next
const value2 = yield* Random.next
console.log(value1, value2)
})
// Same seed produces same sequence
const seeded1 = program.pipe(Random.withSeed("my-seed"))
const seeded2 = program.pipe(Random.withSeed("my-seed"))
// Both will output identical values
Effect.runPromise(seeded1)
Effect.runPromise(seeded2)
withSeed: {
(seed: string | numberseed: string | number): <function (type parameter) A in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>(self: Effect.Effect<A, E, R>(parameter) self: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: import EffectEffect.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>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>) => import EffectEffect.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>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>
<function (type parameter) A in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, R>R>(self: Effect.Effect<A, E, R>(parameter) self: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: import EffectEffect.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>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, R>R>, seed: string | numberseed: string | number): import EffectEffect.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>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, R>R>
} = dual<(...args: Array<any>) => any, <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number) => Effect.Effect<A, E, Exclude<R, never>>>(arity: 2, body: <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number) => Effect.Effect<A, E, Exclude<R, never>>): ((...args: Array<any>) => any) & (<A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number) => Effect.Effect<A, E, Exclude<R, never>>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(2, <function (type parameter) A in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, Exclude<R, never>>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, Exclude<R, never>>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, Exclude<R, never>>R>(
self: Effect.Effect<A, E, R>(parameter) self: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: import EffectEffect.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>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, Exclude<R, never>>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, Exclude<R, never>>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>, seed: string | number): Effect.Effect<A, E, Exclude<R, never>>R>,
seed: string | numberseed: string | number
) => import EffectEffect.const provideService: {
<I, S>(service: Context.Key<I, S>): {
(implementation: S): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, Exclude<R, I>>
<A, E, R>(
self: Effect<A, E, R>,
implementation: S
): Effect<A, E, Exclude<R, I>>
}
<I, S>(
service: Context.Key<I, S>,
implementation: S
): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, Exclude<R, I>>
<A, E, R, I, S>(
self: Effect<A, E, R>,
service: Context.Key<I, S>,
implementation: S
): Effect<A, E, Exclude<R, I>>
}
provideService(self: Effect.Effect<A, E, R>(parameter) self: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self, const Random: Context.Reference<{
nextIntUnsafe(): number
nextDoubleUnsafe(): number
}>
const Random: {
key: string;
Service: {
nextIntUnsafe: () => number;
nextDoubleUnsafe: () => number;
};
defaultValue: () => Shape;
of: (this: void, self: { nextIntUnsafe(): number; nextDoubleUnsafe(): number }) => { nextIntUnsafe(): number; nextDoubleUnsafe(): number };
context: (self: { nextIntUnsafe(): number; nextDoubleUnsafe(): number }) => Context.Context<never>;
use: (f: (service: { nextIntUnsafe(): number; nextDoubleUnsafe(): number }) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
useSync: (f: (service: { nextIntUnsafe(): number; nextDoubleUnsafe(): number }) => A) => Effect.Effect<A, never, never>;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Represents a service for generating pseudo-random numbers.
When to use
Use to access or provide the random-number generator service used by Effect
programs.
Gotchas
The default implementation is based on Math.random and is not
cryptographically secure. Replace the service with a cryptographically secure
implementation before using these generators for security-sensitive values.
Example (Accessing the random service)
import { Effect, Random } from "effect"
const program = Effect.gen(function*() {
const float = yield* Random.next
const integer = yield* Random.nextInt
const inRange = yield* Random.nextIntBetween(1, 100)
console.log("Float:", float)
console.log("Integer:", integer)
console.log("In range:", inRange)
})
Random, function ISAAC_CSPRNG(
userSeed?: string | number
): {
nextIntUnsafe: () => number
nextDoubleUnsafe: () => number
}
ISAAC_CSPRNG(seed: string | numberseed)))