ServeRequirements<Impl>The union of every handler's run-time requirement R in a serve impl — extracted from the
impl value (not a mapped-type parameter), so serve can infer it. Each member is one of the four
ServeMethod forms; a member that requires nothing contributes never.
export type type ServeRequirements<Impl> = {
[K in keyof Impl]: Impl[K] extends (
payload: never
) => Effect.Effect<unknown, unknown, infer R>
? R
: Impl[K] extends (
payload: never
) => Stream.Stream<
unknown,
unknown,
infer R
>
? R
: Impl[K] extends Effect.Effect<
unknown,
unknown,
infer R
>
? R
: Impl[K] extends Stream.Stream<
unknown,
unknown,
infer R
>
? R
: never
}[keyof Impl]
The union of every handler's run-time requirement R in a
serve
impl — extracted from the
impl value (not a mapped-type parameter), so serve can infer it. Each member is one of the four
ServeMethod
forms; a member that requires nothing contributes never.
ServeRequirements<function (type parameter) Impl in type ServeRequirements<Impl>Impl> = {
[function (type parameter) KK in keyof function (type parameter) Impl in type ServeRequirements<Impl>Impl]: function (type parameter) Impl in type ServeRequirements<Impl>Impl[function (type parameter) KK] extends (payload: neverpayload: never) => 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<unknown, unknown, infer function (type parameter) RR>
? function (type parameter) RR
: function (type parameter) Impl in type ServeRequirements<Impl>Impl[function (type parameter) KK] extends (payload: neverpayload: never) => import StreamStream.interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<unknown, unknown, infer function (type parameter) RR>
? function (type parameter) RR
: function (type parameter) Impl in type ServeRequirements<Impl>Impl[function (type parameter) KK] extends 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<unknown, unknown, infer function (type parameter) RR>
? function (type parameter) RR
: function (type parameter) Impl in type ServeRequirements<Impl>Impl[function (type parameter) KK] extends import StreamStream.interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<unknown, unknown, infer function (type parameter) RR>
? function (type parameter) RR
: never;
}[keyof function (type parameter) Impl in type ServeRequirements<Impl>Impl];