(impl: Partial<Stdio>): Layer.Layer<Stdio>Creates a test layer for Stdio.
When to use
Use to provide deterministic standard I/O in tests while overriding only the command-line arguments, input stream, or output sinks relevant to the case.
Details
Any provided fields override defaults. By default, arguments are empty, standard output and error are draining sinks, and standard input is an empty stream.
export const const layerTest: (
impl: Partial<Stdio>
) => Layer.Layer<Stdio>
Creates a test layer for Stdio.
When to use
Use to provide deterministic standard I/O in tests while overriding only the
command-line arguments, input stream, or output sinks relevant to the case.
Details
Any provided fields override defaults. By default, arguments are empty,
standard output and error are draining sinks, and standard input is an empty
stream.
layerTest = (impl: Partial<Stdio>impl: type Partial<T> = {
[P in keyof T]?: T[P] | undefined
}
Make all properties in T optional
Partial<Stdio>): import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<Stdio> =>
import LayerLayer.const succeed: {
<I, S>(service: Context.Key<I, S>): (
resource: S
) => Layer<I>
<I, S>(
service: Context.Key<I, S>,
resource: Types.NoInfer<S>
): Layer<I>
}
succeed(
const Stdio: Context.Service<Stdio, Stdio>const Stdio: {
key: string;
Service: {
args: Effect.Effect<ReadonlyArray<string>>;
stdout: (options?: { readonly endOnDone?: boolean | undefined }) => Sink.Sink<void, string | Uint8Array, never, PlatformError>;
stderr: (options?: { readonly endOnDone?: boolean | undefined }) => Sink.Sink<void, string | Uint8Array, never, PlatformError>;
stdin: Stream.Stream<Uint8Array, PlatformError>;
};
of: (this: void, self: Stdio) => Stdio;
context: (self: Stdio) => Context.Context<Stdio>;
use: (f: (service: Stdio) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Stdio | R>;
useSync: (f: (service: Stdio) => A) => Effect.Effect<A, never, Stdio>;
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;
}
Defines the service interface for process standard I/O.
When to use
Use to depend on command-line arguments and standard I/O through the Effect
environment.
Details
The service provides command-line arguments, sinks for standard output and
standard error, and a stream of standard input bytes. I/O operations can fail
with PlatformError.
Service tag for process standard I/O.
When to use
Use when you need command-line arguments or standard I/O streams supplied by
an effect's environment.
Stdio,
const make: (
options: Omit<Stdio, TypeId>
) => Stdio
Creates a Stdio service implementation from the provided fields and
attaches the Stdio type identifier.
When to use
Use when you need to assemble a concrete Stdio service from command-line
arguments and standard I/O implementations.
Details
The returned service reuses the supplied fields unchanged and only adds the
Stdio type identifier; it does not create a Layer or provide defaults.
make({
args: Effect.Effect<
Array<never>,
never,
never
>
(property) args: {
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;
}
args: import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed([]),
function stdout(options?: {
readonly endOnDone?: boolean | undefined;
}): Sink.Sink<void, string | Uint8Array, never, PlatformError>
stdout: () => import SinkSink.const drain: Sink<void, unknown>const drain: {
transform: (upstream: Pull.Pull<NonEmptyReadonlyArray<In>, never, void>, scope: Scope.Scope) => Effect.Effect<End<A, L>, E, R>;
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; <…;
}
Consumes and ignores all stream inputs.
When to use
Use to consume all upstream input and complete with void when the input
values and any aggregate result are not needed.
drain,
function stderr(options?: {
readonly endOnDone?: boolean | undefined;
}): Sink.Sink<void, string | Uint8Array, never, PlatformError>
stderr: () => import SinkSink.const drain: Sink<void, unknown>const drain: {
transform: (upstream: Pull.Pull<NonEmptyReadonlyArray<In>, never, void>, scope: Scope.Scope) => Effect.Effect<End<A, L>, E, R>;
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; <…;
}
Consumes and ignores all stream inputs.
When to use
Use to consume all upstream input and complete with void when the input
values and any aggregate result are not needed.
drain,
stdin: Stream.Stream<never, never, never>(property) stdin: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
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; <…;
}
stdin: import StreamStream.const empty: Stream<never>const empty: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
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; <…;
}
Creates an empty stream.
Example (Creating an empty stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const values = yield* Stream.empty.pipe(Stream.runCollect)
yield* Console.log(values)
})
Effect.runPromise(program)
// []
empty,
...impl: Partial<Stdio>impl
})
)