ServeMethod<M, R>export type type ServeMethod<
M extends AnyMethod,
R
> = M["stream"] extends true
? [M["payload"]] extends [undefined]
? Stream.Stream<SuccessOf<M>, ErrorOf<M>, R>
: (
payload: PayloadOf<M>
) => Stream.Stream<
SuccessOf<M>,
ErrorOf<M>,
R
>
: [M["payload"]] extends [undefined]
? Effect.Effect<SuccessOf<M>, ErrorOf<M>, R>
: (
payload: PayloadOf<M>
) => Effect.Effect<
SuccessOf<M>,
ErrorOf<M>,
R
>
ServeMethod<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M extends type AnyMethod = Method<
Schema.Top | Schema.Struct.Fields | undefined,
Schema.Top,
Schema.Top,
boolean,
MethodAnnotations,
never
>
Any
Method
, erased — the element type of a
Spec
.
AnyMethod, function (type parameter) R in type ServeMethod<M extends AnyMethod, R>R> = function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M["stream"] extends true
? [function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M["payload"]] extends [undefined]
? 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<type SuccessOf<M extends AnyMethod> =
M["success"]["Type"]
SuccessOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>, type ErrorOf<M extends AnyMethod> =
M["error"]["Type"]
ErrorOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>, function (type parameter) R in type ServeMethod<M extends AnyMethod, R>R>
: (payload: PayloadOf<M>payload: type PayloadOf<M extends AnyMethod> =
M["payload"] extends Schema.Top
? PrettifyPayload<M["payload"]["Type"]>
: M["payload"] extends infer F extends Schema.Struct.Fields
? PrettifyPayload<
Schema.Struct.View<
F,
"Type",
Schema.Struct.TypeOptionalKeys<F>,
Schema.Struct.TypeMutableKeys<F>
>
>
: never
PayloadOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>) => 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<type SuccessOf<M extends AnyMethod> =
M["success"]["Type"]
SuccessOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>, type ErrorOf<M extends AnyMethod> =
M["error"]["Type"]
ErrorOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>, function (type parameter) R in type ServeMethod<M extends AnyMethod, R>R>
: [function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M["payload"]] extends [undefined]
? 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<type SuccessOf<M extends AnyMethod> =
M["success"]["Type"]
SuccessOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>, type ErrorOf<M extends AnyMethod> =
M["error"]["Type"]
ErrorOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>, function (type parameter) R in type ServeMethod<M extends AnyMethod, R>R>
: (payload: PayloadOf<M>payload: type PayloadOf<M extends AnyMethod> =
M["payload"] extends Schema.Top
? PrettifyPayload<M["payload"]["Type"]>
: M["payload"] extends infer F extends Schema.Struct.Fields
? PrettifyPayload<
Schema.Struct.View<
F,
"Type",
Schema.Struct.TypeOptionalKeys<F>,
Schema.Struct.TypeMutableKeys<F>
>
>
: never
PayloadOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>) => 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<type SuccessOf<M extends AnyMethod> =
M["success"]["Type"]
SuccessOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>, type ErrorOf<M extends AnyMethod> =
M["error"]["Type"]
ErrorOf<function (type parameter) M in type ServeMethod<M extends AnyMethod, R>M>, function (type parameter) R in type ServeMethod<M extends AnyMethod, R>R>;