import * as tsplus_module_1 from "@tsplus/stdlib/collections/Chunk/single";
import * as tsplus_module_2 from "@effect/core/stream/Channel/operations/write";
import * as tsplus_module_3 from "@tsplus/stdlib/data/Maybe/fold";
import * as tsplus_module_4 from "@effect/core/collection/Chunk/operations/findEffect";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_6 from "@effect/core/stream/Channel/operations/unwrap";
import * as tsplus_module_7 from "@effect/core/stream/Channel/operations/fail";
import * as tsplus_module_8 from "@effect/core/stream/Channel/operations/unit";
import * as tsplus_module_9 from "@effect/core/stream/Channel/operations/readWith";
import * as tsplus_module_10 from "@effect/core/stream/Channel/operations/pipeTo";
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 fluent ets/Stream findEffect
 */

export function findEffect_(self, f, __tsplusTrace) {
  const loop = tsplus_module_9.readWith(chunk => tsplus_module_6.unwrap(() => tsplus_module_5.map_(tsplus_module_4.findEffect_(chunk, f, __tsplusTrace), option => tsplus_module_3.fold_(option, () => loop, a => tsplus_module_2.write(() => tsplus_module_1.single(a))), __tsplusTrace)), e => tsplus_module_7.fail(() => e), () => tsplus_module_8.unit);
  void 0;
  return new StreamInternal(tsplus_module_10.pipeTo_(self.channel, () => loop));
}
/**
 * Finds the first element emitted by this stream that satisfies the provided
 * effectful predicate.
 *
 * @tsplus static ets/Stream/Aspects findEffect
 */

export const findEffect = (f, __tsplusTrace) => self => findEffect_(self, f, __tsplusTrace);
//# sourceMappingURL=findEffect.mjs.map