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