<In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<
Option.Option<In>,
In,
In,
E,
R
>Creates a sink containing the first value matched by an effectful predicate.
When to use
Use when you need to run effects, fail, or use services while searching for the first matching input.
Details
Returns Option.some with the first input whose predicate result is true,
or Option.none if the upstream stream ends first. If the predicate effect
fails, the sink fails with the same error.
export const const findEffect: <In, E, R>(
predicate: (
input: In
) => Effect.Effect<boolean, E, R>
) => Sink<Option.Option<In>, In, In, E, R>
Creates a sink containing the first value matched by an effectful predicate.
When to use
Use when you need to run effects, fail, or use services while searching for
the first matching input.
Details
Returns Option.some with the first input whose predicate result is true,
or Option.none if the upstream stream ends first. If the predicate effect
fails, the sink fails with the same error.
findEffect = <function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<In>, In, In, E, R>In, function (type parameter) E in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<In>, In, In, E, R>E, function (type parameter) R in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<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<Option.Option<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<Option.Option<In>, In, In, E, R>E, function (type parameter) R in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<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<import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<In>, In, In, E, R>In>, function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<In>, In, In, E, R>In, function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<In>, In, In, E, R>In, function (type parameter) E in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<In>, In, In, E, R>E, function (type parameter) R in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<In>, In, In, 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(
import OptionOption.const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
none<function (type parameter) In in <In, E, R>(predicate: (input: In) => Effect.Effect<boolean, E, R>): Sink<Option.Option<In>, In, In, E, R>In>,
import OptionOption.const isNone: <A>(
self: Option<A>
) => self is None<A>
Checks whether an Option is None (absent).
When to use
Use when you need to branch on an absent Option before accessing .value.
Details
- Acts as a type guard, narrowing to
None<A>
Example (Checking for None)
import { Option } from "effect"
console.log(Option.isNone(Option.some(1)))
// Output: false
console.log(Option.isNone(Option.none()))
// Output: true
isNone,
(acc: Option.Option<In>acc, in_: Inin_) => 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(in_: Inin_), (b: booleanb) => b: booleanb ? import OptionOption.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(in_: Inin_) : acc: Option.Option<In>acc)
)