<S, In, E, R>(
initial: LazyArg<S>,
f: (s: S, input: In) => Effect.Effect<S, E, R>
): Sink<S, In, never, E, R>A sink that reduces its inputs using the provided effectful function f
starting from the specified initial state.
export const const reduceEffect: <S, In, E, R>(
initial: LazyArg<S>,
f: (s: S, input: In) => Effect.Effect<S, E, R>
) => Sink<S, In, never, E, R>
A sink that reduces its inputs using the provided effectful function f
starting from the specified initial state.
reduceEffect = <function (type parameter) S in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>S, function (type parameter) In in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>In, function (type parameter) E in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>E, function (type parameter) R in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>R>(
initial: LazyArg<S>initial: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<function (type parameter) S in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>S>,
f: (
s: S,
input: In
) => Effect.Effect<S, E, R>
f: (s: Ss: function (type parameter) S in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>S, input: Ininput: function (type parameter) In in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>In) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) S in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>S, function (type parameter) E in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>E, function (type parameter) R in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>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) S in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>S, function (type parameter) In in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>In, never, function (type parameter) E in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>E, function (type parameter) R in <S, In, E, R>(initial: LazyArg<S>, f: (s: S, input: In) => Effect.Effect<S, E, R>): Sink<S, In, never, E, R>R> => const reduceWhileEffect: <S, In, E, R>(
initial: LazyArg<S>,
predicate: Predicate<S>,
f: (s: S, input: In) => Effect.Effect<S, E, R>
) => Sink<S, In, In, E, R>
A sink that effectfully reduces input elements from the provided initial
state with f while the specified predicate returns true.
reduceWhileEffect(initial: LazyArg<S>initial, const constTrue: LazyArg<boolean>Returns true when called.
When to use
Use when you need a thunk that returns true on every invocation.
Example (Returning true from a thunk)
import { Function } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(Function.constTrue(), true)
constTrue, f: (
s: S,
input: In
) => Effect.Effect<S, E, R>
f) as any