(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.type Layer.Layer = /*unresolved*/ anyLayer<Stdio> =>
import LayerLayer.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.succeed([]),
function stdout(options?: {
readonly endOnDone?: boolean | undefined;
}): Sink.Sink<void, string | Uint8Array, never, PlatformError>
stdout: () => import SinkSink.drain,
function stderr(options?: {
readonly endOnDone?: boolean | undefined;
}): Sink.Sink<void, string | Uint8Array, never, PlatformError>
stderr: () => import SinkSink.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
})
)