<In>(predicate: Predicate<In>): Sink<boolean, In, In>A sink that returns whether all elements satisfy the specified predicate.
When to use
Use to reduce a stream to a boolean that is true only when every input satisfies a pure predicate.
export const const every: <In>(
predicate: Predicate<In>
) => Sink<boolean, In, In>
A sink that returns whether all elements satisfy the specified predicate.
When to use
Use to reduce a stream to a boolean that is true only when every input
satisfies a pure predicate.
every = <function (type parameter) In in <In>(predicate: Predicate<In>): Sink<boolean, In, In>In>(predicate: Predicate<In>predicate: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) In in <In>(predicate: Predicate<In>): Sink<boolean, In, In>In>): 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<boolean, function (type parameter) In in <In>(predicate: Predicate<In>): Sink<boolean, In, In>In, function (type parameter) In in <In>(predicate: Predicate<In>): Sink<boolean, In, In>In> =>
const fold: <S, In, E = never, R = never>(
s: LazyArg<S>,
contFn: Predicate<S>,
f: (s: S, input: In) => Effect.Effect<S, E, R>
) => Sink<S, In, In, E, R>
A sink that folds its inputs with the provided function, termination
predicate and initial state.
When to use
Use to accumulate stream input element by element with an effectful step and
stop based on the accumulated state.
Details
The initial state is evaluated lazily. Each input element is folded with the
effectful function, and the sink continues while contFn returns true. If
the sink stops in the middle of a pulled array, the remaining elements from
that array are returned as leftovers.
fold(
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,
const identity: <A>(a: A) => AReturns its input argument unchanged.
When to use
Use to return a value unchanged where a function is required.
Example (Returning the same value)
import { identity } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(identity(5), 5)
identity,
(_: boolean_, a: Ina) => 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(predicate: Predicate<In>predicate(a: Ina))
)