<In, Out extends In>(refinement: Refinement<In, Out>): Sink<
Option.Option<Out>,
In,
In
>
<In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>Creates a sink containing the first value matched by a synchronous predicate.
When to use
Use to scan stream input until the first matching element is found and return
that element as an Option.
Details
Returns Option.none if the upstream stream ends before a match is found.
Refinement predicates narrow the returned value type. The matching input is
consumed; any later elements from the same pulled array are returned as
leftovers.
export const const find: {
<In, Out extends In>(
refinement: Refinement<In, Out>
): Sink<Option.Option<Out>, In, In>
<In>(predicate: Predicate<In>): Sink<
Option.Option<In>,
In,
In
>
}
Creates a sink containing the first value matched by a synchronous predicate.
When to use
Use to scan stream input until the first matching element is found and return
that element as an Option.
Details
Returns Option.none if the upstream stream ends before a match is found.
Refinement predicates narrow the returned value type. The matching input is
consumed; any later elements from the same pulled array are returned as
leftovers.
find: {
<function (type parameter) In in <In, Out extends In>(refinement: Refinement<In, Out>): Sink<Option.Option<Out>, In, In>In, function (type parameter) Out in <In, Out extends In>(refinement: Refinement<In, Out>): Sink<Option.Option<Out>, In, In>Out extends function (type parameter) In in <In, Out extends In>(refinement: Refinement<In, Out>): Sink<Option.Option<Out>, In, In>In>(refinement: Refinement<In, Out>refinement: import RefinementRefinement<function (type parameter) In in <In, Out extends In>(refinement: Refinement<In, Out>): Sink<Option.Option<Out>, In, In>In, function (type parameter) Out in <In, Out extends In>(refinement: Refinement<In, Out>): Sink<Option.Option<Out>, In, In>Out>): 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.Option = /*unresolved*/ anyOption<function (type parameter) Out in <In, Out extends In>(refinement: Refinement<In, Out>): Sink<Option.Option<Out>, In, In>Out>, function (type parameter) In in <In, Out extends In>(refinement: Refinement<In, Out>): Sink<Option.Option<Out>, In, In>In, function (type parameter) In in <In, Out extends In>(refinement: Refinement<In, Out>): Sink<Option.Option<Out>, In, In>In>
<function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>In>(predicate: Predicate<In>predicate: import PredicatePredicate<function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, 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<import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>In>, function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>In, function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>In>
} = <function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>In>(predicate: Predicate<In>predicate: import PredicatePredicate<function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, 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<import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>In>, function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>In, function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>In> =>
const reduceWhile: <S, In>(
initial: LazyArg<S>,
predicate: Predicate<S>,
f: (s: S, input: In) => S
) => Sink<S, In, In>
A sink that reduces input elements from the provided initial state with
f while the specified predicate returns true.
reduceWhile(
import OptionOption.none<function (type parameter) In in <In>(predicate: Predicate<In>): Sink<Option.Option<In>, In, In>In>,
import OptionOption.isNone,
(acc: Option.Option<In>acc, in_: Inin_) => predicate: Predicate<In>predicate(in_: Inin_) ? import OptionOption.some(in_: Inin_) : acc: Option.Option<In>acc
)