// ets_tracing: off import * as CK from "../../../../Collections/Immutable/Chunk/index.js" import type { Predicate, Refinement } from "../../../../Function/index.js" import * as O from "../../../../Option/index.js" import * as CH from "../../Channel/index.js" import * as C from "../core.js" /** * Finds the first element emitted by this stream that satisfies the provided predicate. */ export function find_( self: C.Stream, f: Refinement ): C.Stream export function find_( self: C.Stream, f: Predicate ): C.Stream export function find_( self: C.Stream, f: Predicate ): C.Stream { const loop: CH.Channel, unknown, E, CK.Chunk, any> = CH.readWith( (in_) => O.fold_( CK.find_(in_, f), () => loop, (i) => CH.write(CK.single(i)) ), (e) => CH.fail(e), (_) => CH.unit ) return new C.Stream(self.channel[">>>"](loop)) } /** * Finds the first element emitted by this stream that satisfies the provided predicate. * @ets_data_first find_ */ export function find(f: Predicate) { return (self: C.Stream) => find_(self, f) }