Services<T>Extract the services type from a Stream type.
Example (Extracting the services type from a Stream type)
import type { Stream } from "effect"
interface Database {
query: (sql: string) => unknown
}
type NumberStream = Stream.Stream<number, string, { db: Database }>
type RequiredServices = Stream.Services<NumberStream>
// RequiredServices is { db: Database }export type type Services<
T extends Stream<any, any, any>
> = [T] extends [
Stream<infer _A, infer _E, infer _R>
]
? _R
: never
Extract the services type from a Stream type.
Example (Extracting the services type from a Stream type)
import type { Stream } from "effect"
interface Database {
query: (sql: string) => unknown
}
type NumberStream = Stream.Stream<number, string, { db: Database }>
type RequiredServices = Stream.Services<NumberStream>
// RequiredServices is { db: Database }
Services<function (type parameter) T in type Services<T extends Stream<any, any, any>>T extends 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<any, any, any>> = [function (type parameter) T in type Services<T extends Stream<any, any, any>>T] extends [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<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) _R_R>] ? function (type parameter) _R_R
: never