<In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<
Array<In>,
In,
In,
E,
R
>Collects input elements effectfully until the predicate returns true,
including the matching element in the result.
Details
If the predicate effect fails, the sink fails with the same error.
export const const takeUntilEffect: <In, E, R>(
predicate: (
input: In
) => Effect.Effect<boolean, E, R>
) => Sink<Array<In>, In, In, E, R>
Collects input elements effectfully until the predicate returns true,
including the matching element in the result.
Details
If the predicate effect fails, the sink fails with the same error.
takeUntilEffect = <function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, E, R>In, function (type parameter) E in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, E, R>E, function (type parameter) R in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, E, R>R>(
predicate: (
input: In
) => Effect.Effect<boolean, E, R>
predicate: (input: Ininput: function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, 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<boolean, function (type parameter) E in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, E, R>E, function (type parameter) R in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, 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<interface Array<T>Array<function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, E, R>In>, function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, E, R>In, function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, E, R>In, function (type parameter) E in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, E, R>E, function (type parameter) R in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Array<In>, In, In, E, R>R> =>
const suspend: <A, In, L, E, R>(
evaluate: LazyArg<Sink<A, In, L, E, R>>
) => Sink<A, In, L, E, R>
A sink that is created from a lazily evaluated sink.
suspend(() => {
let let done: booleandone = false
return const takeWhileEffect: {
<In, E, R>(
predicate: (
input: In
) => Effect.Effect<boolean, E, R>
): Sink<Array<In>, In, In, E, R>
}
Collects input elements effectfully while the predicate succeeds.
Details
The first input for which the predicate returns false is consumed and
excluded from the result. Any later elements from the same pulled array are
returned as leftovers.
takeWhileEffect((input: Ininput) => {
if (let done: booleandone) {
return import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(false)
}
return import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map(predicate: (
input: In
) => Effect.Effect<boolean, E, R>
predicate(input: Ininput), (b: booleanb) => {
let done: booleandone = b: booleanb
return true
})
})
})