<I, S>(key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): <A, E, R>(
self: Stream<A, E, R>
) => Stream<A, E, R | I>
<A, E, R, I, S>(
self: Stream<A, E, R>,
key: Context.Key<I, S>,
f: (service: NoInfer<S>) => S
): Stream<A, E, R | I>Updates a single service in the stream environment by applying a function.
Example (Updating a stream service)
import { Console, Context, Effect, Stream } from "effect"
class Counter extends Context.Service<Counter, { count: number }>()("Counter") {}
const stream = Stream.fromEffect(Effect.service(Counter)).pipe(
Stream.updateService(Counter, (counter) => ({ count: counter.count + 1 }))
)
const program = Effect.gen(function*() {
const counters = yield* Stream.runCollect(stream)
yield* Console.log(`Updated count: ${counters[0].count}`)
})
Effect.runPromise(Effect.provideService(program, Counter, { count: 0 }))
// Output: Updated count: 1export const const updateService: {
<I, S>(
key: Context.Key<I, S>,
f: (service: NoInfer<S>) => S
): <A, E, R>(
self: Stream<A, E, R>
) => Stream<A, E, R | I>
<A, E, R, I, S>(
self: Stream<A, E, R>,
key: Context.Key<I, S>,
f: (service: NoInfer<S>) => S
): Stream<A, E, R | I>
}
Updates a single service in the stream environment by applying a function.
Example (Updating a stream service)
import { Console, Context, Effect, Stream } from "effect"
class Counter extends Context.Service<Counter, { count: number }>()("Counter") {}
const stream = Stream.fromEffect(Effect.service(Counter)).pipe(
Stream.updateService(Counter, (counter) => ({ count: counter.count + 1 }))
)
const program = Effect.gen(function*() {
const counters = yield* Stream.runCollect(stream)
yield* Console.log(`Updated count: ${counters[0].count}`)
})
Effect.runPromise(Effect.provideService(program, Counter, { count: 0 }))
// Output: Updated count: 1
updateService: {
<function (type parameter) I in <I, S>(key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R | I>I, function (type parameter) S in <I, S>(key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R | I>S>(
key: Context.Key<I, S>(parameter) key: {
Identifier: Identifier;
Service: Shape;
key: string;
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;
}
key: import ContextContext.type Context.Key = /*unresolved*/ anyKey<function (type parameter) I in <I, S>(key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R | I>I, function (type parameter) S in <I, S>(key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R | I>S>,
f: (service: NoInfer<S>) => Sf: (service: NoInfer<S>service: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) S in <I, S>(key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R | I>S>) => function (type parameter) S in <I, S>(key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R | I>S
): <function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<A, E, R | I>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<A, E, R | I>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<A, E, R | I>R>(
self: Stream<A, E, R>(parameter) self: {
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; <…;
}
self: 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<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<A, E, R | I>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<A, E, R | I>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<A, E, R | I>R>
) => 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<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<A, E, R | I>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<A, E, R | I>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<A, E, R | I>R | function (type parameter) I in <I, S>(key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, R | I>I>
<function (type parameter) A in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>A, function (type parameter) E in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>E, function (type parameter) R in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>R, function (type parameter) I in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>I, function (type parameter) S in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>S>(
self: Stream<A, E, R>(parameter) self: {
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; <…;
}
self: 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<function (type parameter) A in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>A, function (type parameter) E in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>E, function (type parameter) R in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>R>,
key: Context.Key<I, S>(parameter) key: {
Identifier: Identifier;
Service: Shape;
key: string;
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;
}
key: import ContextContext.type Context.Key = /*unresolved*/ anyKey<function (type parameter) I in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>I, function (type parameter) S in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>S>,
f: (service: NoInfer<S>) => Sf: (service: NoInfer<S>service: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) S in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>S>) => function (type parameter) S in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>S
): 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<function (type parameter) A in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>A, function (type parameter) E in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>E, function (type parameter) R in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>R | function (type parameter) I in <A, E, R, I, S>(self: Stream<A, E, R>, key: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>I>
} = import dualdual(3, <function (type parameter) A in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>A, function (type parameter) E in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>E, function (type parameter) R in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>R, function (type parameter) I in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>I, function (type parameter) S in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>S>(
self: Stream<A, E, R>(parameter) self: {
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; <…;
}
self: 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<function (type parameter) A in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>A, function (type parameter) E in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>E, function (type parameter) R in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>R>,
service: Context.Key<I, S>(parameter) service: {
Identifier: Identifier;
Service: Shape;
key: string;
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;
}
service: import ContextContext.type Context.Key = /*unresolved*/ anyKey<function (type parameter) I in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>I, function (type parameter) S in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>S>,
f: (service: NoInfer<S>) => Sf: (service: NoInfer<S>service: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) S in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>S>) => function (type parameter) S in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>S
): 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<function (type parameter) A in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>A, function (type parameter) E in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>E, function (type parameter) R in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>R | function (type parameter) I in <A, E, R, I, S>(self: Stream<A, E, R>, service: Context.Key<I, S>, f: (service: NoInfer<S>) => S): Stream<A, E, R | I>I> =>
const updateContext: {
<R, R2>(
f: (
context: Context.Context<R2>
) => Context.Context<R>
): <A, E>(
self: Stream<A, E, R>
) => Stream<A, E, R2>
<A, E, R, R2>(
self: Stream<A, E, R>,
f: (
context: Context.Context<R2>
) => Context.Context<R>
): Stream<A, E, R2>
}
updateContext(self: Stream<A, E, R>(parameter) self: {
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; <…;
}
self, (context: Context.Context<R | I>(parameter) context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context) =>
import ContextContext.add(
context: Context.Context<R | I>(parameter) context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context,
service: Context.Key<I, S>(parameter) service: {
Identifier: Identifier;
Service: Shape;
key: string;
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;
}
service,
f: (service: NoInfer<S>) => Sf(import ContextContext.get(context: Context.Context<R | I>(parameter) context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
context, service: Context.Key<I, S>(parameter) service: {
Identifier: Identifier;
Service: Shape;
key: string;
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;
}
service))
)))