<A2, E2, R2>(
that: Effect<A2, E2, R2>,
options?: { readonly concurrent?: boolean | undefined } | undefined
): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(
self: Effect<A, E, R>,
that: Effect<A2, E2, R2>,
options?: { readonly concurrent?: boolean | undefined }
): Effect<[A, A2], E | E2, R | R2>Combines two effects into a single effect, producing a tuple with the results of both effects.
When to use
Use to combine exactly two effects into a tuple.
Details
The zip function executes the first effect (left) and then the second effect (right).
Once both effects succeed, their results are combined into a tuple.
Concurrency:
By default, zip processes the effects sequentially. To execute the effects concurrently,
use the { concurrent: true } option.
Example (Combining two effects sequentially)
import { Effect } from "effect"
const task1 = Effect.succeed(1).pipe(
Effect.delay("200 millis"),
Effect.tap(Effect.log("task1 done"))
)
const task2 = Effect.succeed("hello").pipe(
Effect.delay("100 millis"),
Effect.tap(Effect.log("task2 done"))
)
// Combine the two effects together
//
// ┌─── Effect<[number, string], never, never>
// ▼
const program = Effect.zip(task1, task2)
Effect.runPromise(program).then(console.log)
// Output:
// timestamp=... level=INFO fiber=#0 message="task1 done"
// timestamp=... level=INFO fiber=#0 message="task2 done"
// [ 1, 'hello' ]Example (Combining two effects concurrently)
import { Effect } from "effect"
const task1 = Effect.succeed(1).pipe(
Effect.delay("200 millis"),
Effect.tap(Effect.log("task1 done"))
)
const task2 = Effect.succeed("hello").pipe(
Effect.delay("100 millis"),
Effect.tap(Effect.log("task2 done"))
)
// Run both effects concurrently using the concurrent option
const program = Effect.zip(task1, task2, { concurrent: true })
Effect.runPromise(program).then(console.log)
// Output:
// timestamp=... level=INFO fiber=#0 message="task2 done"
// timestamp=... level=INFO fiber=#0 message="task1 done"
// [ 1, 'hello' ]export const const zip: {
<A2, E2, R2>(
that: Effect<A2, E2, R2>,
options?:
| {
readonly concurrent?:
| boolean
| undefined
}
| undefined
): <A, E, R>(
self: Effect<A, E, R>
) => Effect<[A, A2], E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(
self: Effect<A, E, R>,
that: Effect<A2, E2, R2>,
options?: {
readonly concurrent?: boolean | undefined
}
): Effect<[A, A2], E | E2, R | R2>
}
Combines two effects into a single effect, producing a tuple with the results of both effects.
When to use
Use to combine exactly two effects into a tuple.
Details
The zip function executes the first effect (left) and then the second effect (right).
Once both effects succeed, their results are combined into a tuple.
Concurrency:
By default, zip processes the effects sequentially. To execute the effects concurrently,
use the { concurrent: true } option.
Example (Combining two effects sequentially)
import { Effect } from "effect"
const task1 = Effect.succeed(1).pipe(
Effect.delay("200 millis"),
Effect.tap(Effect.log("task1 done"))
)
const task2 = Effect.succeed("hello").pipe(
Effect.delay("100 millis"),
Effect.tap(Effect.log("task2 done"))
)
// Combine the two effects together
//
// ┌─── Effect<[number, string], never, never>
// ▼
const program = Effect.zip(task1, task2)
Effect.runPromise(program).then(console.log)
// Output:
// timestamp=... level=INFO fiber=#0 message="task1 done"
// timestamp=... level=INFO fiber=#0 message="task2 done"
// [ 1, 'hello' ]
Example (Combining two effects concurrently)
import { Effect } from "effect"
const task1 = Effect.succeed(1).pipe(
Effect.delay("200 millis"),
Effect.tap(Effect.log("task1 done"))
)
const task2 = Effect.succeed("hello").pipe(
Effect.delay("100 millis"),
Effect.tap(Effect.log("task2 done"))
)
// Run both effects concurrently using the concurrent option
const program = Effect.zip(task1, task2, { concurrent: true })
Effect.runPromise(program).then(console.log)
// Output:
// timestamp=... level=INFO fiber=#0 message="task2 done"
// timestamp=... level=INFO fiber=#0 message="task1 done"
// [ 1, 'hello' ]
zip: {
<function (type parameter) A2 in <A2, E2, R2>(that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
} | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
A2, function (type parameter) E2 in <A2, E2, R2>(that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
} | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
E2, function (type parameter) R2 in <A2, E2, R2>(that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
} | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
R2>(
that: Effect<A2, E2, R2>(parameter) that: {
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;
}
that: 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) A2 in <A2, E2, R2>(that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
} | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
A2, function (type parameter) E2 in <A2, E2, R2>(that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
} | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
E2, function (type parameter) R2 in <A2, E2, R2>(that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
} | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
R2>,
options: | {
readonly concurrent?: boolean | undefined
}
| undefined
options?: { readonly concurrent?: boolean | undefinedconcurrent?: boolean | undefined } | undefined
): <function (type parameter) A in <A, E, R>(self: Effect<A, E, R>): Effect<[A, A2], E2 | E, R2 | R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<[A, A2], E2 | E, R2 | R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<[A, A2], E2 | E, R2 | R>R>(self: 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: 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<A, E, R>): Effect<[A, A2], E2 | E, R2 | R>A, function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<[A, A2], E2 | E, R2 | R>E, function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<[A, A2], E2 | E, R2 | R>R>) => 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<A, E, R>): Effect<[A, A2], E2 | E, R2 | R>A, function (type parameter) A2 in <A2, E2, R2>(that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
} | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
A2], function (type parameter) E2 in <A2, E2, R2>(that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
} | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
E2 | function (type parameter) E in <A, E, R>(self: Effect<A, E, R>): Effect<[A, A2], E2 | E, R2 | R>E, function (type parameter) R2 in <A2, E2, R2>(that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
} | undefined): <A, E, R>(self: Effect<A, E, R>) => Effect<[A, A2], E2 | E, R2 | R>
R2 | function (type parameter) R in <A, E, R>(self: Effect<A, E, R>): Effect<[A, A2], E2 | E, R2 | R>R>
<function (type parameter) A in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
A, function (type parameter) E in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
E, function (type parameter) R in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
R, function (type parameter) A2 in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
A2, function (type parameter) E2 in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
E2, function (type parameter) R2 in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
R2>(
self: 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: 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, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
A, function (type parameter) E in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
E, function (type parameter) R in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
R>,
that: Effect<A2, E2, R2>(parameter) that: {
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;
}
that: 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) A2 in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
A2, function (type parameter) E2 in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
E2, function (type parameter) R2 in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
R2>,
options: | {
readonly concurrent?: boolean | undefined
}
| undefined
options?: { readonly concurrent?: boolean | undefinedconcurrent?: boolean | undefined }
): 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, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
A, function (type parameter) A2 in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
A2], function (type parameter) E in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
E | function (type parameter) E2 in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
E2, function (type parameter) R in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
R | function (type parameter) R2 in <A, E, R, A2, E2, R2>(self: Effect<A, E, R>, that: Effect<A2, E2, R2>, options?: {
readonly concurrent?: boolean | undefined;
}): Effect<[A, A2], E | E2, R | R2>
R2>
} = import internalinternal.const zip: {
<A2, E2, R2>(
that: Effect.Effect<A2, E2, R2>,
options?:
| {
readonly concurrent?:
| boolean
| undefined
}
| undefined
): <A, E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<[A, A2], E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(
self: Effect.Effect<A, E, R>,
that: Effect.Effect<A2, E2, R2>,
options?: {
readonly concurrent?: boolean | undefined
}
): Effect.Effect<[A, A2], E | E2, R | R2>
}
zip