import { concreteStream, StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal" /** * Finds the first element emitted by this stream that satisfies the provided * predicate. * * @tsplus static effect/core/stream/Stream.Aspects find * @tsplus pipeable effect/core/stream/Stream find */ export function find( f: Refinement ): (self: Stream) => Stream export function find( f: Predicate ): (self: Stream) => Stream export function find(f: Predicate) { return (self: Stream): Stream => { const loop: Channel, unknown, E, Chunk, any> = Channel.readWith( (chunk) => chunk.find(f).fold(loop, (a) => Channel.write(Chunk.single(a))), Channel.fail, (_) => Channel.unit ) concreteStream(self) return new StreamInternal(self.channel >> loop) } }