<A, In, L, E, R, R2>(
effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>
): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>Creates a sink produced from a scoped effect.
Example (Unwrapping a sink effect)
import { Console, Effect, Sink, Stream } from "effect"
// Create a sink from an effect that produces a sink
const sinkEffect = Effect.succeed(
Sink.forEach((item: number) => Console.log(`Item: ${item}`))
)
const sink = Sink.unwrap(sinkEffect)
// Use it with a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program)
// Output:
// Item: 1
// Item: 2
// Item: 3export const const unwrap: <A, In, L, E, R, R2>(
effect: Effect.Effect<
Sink<A, In, L, E, R2>,
E,
R
>
) => Sink<
A,
In,
L,
E,
Exclude<R, Scope.Scope> | R2
>
Creates a sink produced from a scoped effect.
Example (Unwrapping a sink effect)
import { Console, Effect, Sink, Stream } from "effect"
// Create a sink from an effect that produces a sink
const sinkEffect = Effect.succeed(
Sink.forEach((item: number) => Console.log(`Item: ${item}`))
)
const sink = Sink.unwrap(sinkEffect)
// Use it with a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program)
// Output:
// Item: 1
// Item: 2
// Item: 3
unwrap = <function (type parameter) A in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>A, function (type parameter) In in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>In, function (type parameter) L in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>L, function (type parameter) E in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>E, function (type parameter) R in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>R, function (type parameter) R2 in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>R2>(
effect: Effect.Effect<
Sink<A, In, L, E, R2>,
E,
R
>
(parameter) effect: {
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;
}
effect: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface Sink<out A, in In = unknown, out L = never, out E = never, out R = never>A Sink<A, In, L, E, R> is used to consume elements produced by a Stream.
You can think of a sink as a function that will consume a variable amount of
In elements (could be 0, 1, or many), might fail with an error of type E,
and will eventually yield a value of type A together with a remainder of
type L (i.e. any leftovers).
Example (Running a sink with a stream)
import { Effect, Sink, Stream } from "effect"
// Create a simple sink that always succeeds with a value
const sink: Sink.Sink<number> = Sink.succeed(42)
// Use the sink to consume a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program).then(console.log)
// Output: 42
Namespace containing types and interfaces for Sink variance and type relationships.
Sink<function (type parameter) A in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>A, function (type parameter) In in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>In, function (type parameter) L in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>L, function (type parameter) E in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>E, function (type parameter) R2 in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>R2>, function (type parameter) E in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>E, function (type parameter) R in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>R>
): interface Sink<out A, in In = unknown, out L = never, out E = never, out R = never>A Sink<A, In, L, E, R> is used to consume elements produced by a Stream.
You can think of a sink as a function that will consume a variable amount of
In elements (could be 0, 1, or many), might fail with an error of type E,
and will eventually yield a value of type A together with a remainder of
type L (i.e. any leftovers).
Example (Running a sink with a stream)
import { Effect, Sink, Stream } from "effect"
// Create a simple sink that always succeeds with a value
const sink: Sink.Sink<number> = Sink.succeed(42)
// Use the sink to consume a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program).then(console.log)
// Output: 42
Namespace containing types and interfaces for Sink variance and type relationships.
Sink<function (type parameter) A in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>A, function (type parameter) In in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>In, function (type parameter) L in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>L, function (type parameter) E in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>E, type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) R in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>R, import ScopeScope.type Scope.Scope = /*unresolved*/ anyScope> | function (type parameter) R2 in <A, In, L, E, R, R2>(effect: Effect.Effect<Sink<A, In, L, E, R2>, E, R>): Sink<A, In, L, E, Exclude<R, Scope.Scope> | R2>R2> => const fromChannel: <L, In, E, A, R>(
channel: Channel.Channel<
never,
E,
End<A, L>,
NonEmptyReadonlyArray<In>,
never,
void,
R
>
) => Sink<A, In, L, E, R>
Creates a sink from a Channel.
When to use
Use to create a Sink from a Channel that processes non-empty arrays of
input values.
fromChannel(import ChannelChannel.unwrap(import EffectEffect.map(effect: Effect.Effect<
Sink<A, In, L, E, R2>,
E,
R
>
(parameter) effect: {
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;
}
effect, const toChannel: <A, In, L, E, R>(
self: Sink<A, In, L, E, R>
) => Channel.Channel<
never,
E,
End<A, L>,
NonEmptyReadonlyArray<In>,
never,
void,
R
>
Creates a Channel from a Sink.
Example (Converting a sink to a channel)
import { Sink } from "effect"
// Create a sink and extract its channel
const sink = Sink.succeed(42)
const channel = Sink.toChannel(sink)
toChannel)))