import * as tsplus_module_1 from "@effect/core/io/Effect/operations/succeed";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/flatMap";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/succeedNow";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/suspendSucceed";
/**
 * Determines whether any element of the `Collection<A>` satisfies the effectual
 * predicate `f`.
 *
 * @tsplus static ets/Effect/Ops exists
 */

export function exists(as, f, __tsplusTrace) {
  return tsplus_module_2.flatMap_(tsplus_module_1.succeed(as, __tsplusTrace), Collection => loop(Collection[Symbol.iterator](), f, __tsplusTrace), __tsplusTrace);
}

function loop(iterator, f, __tsplusTrace) {
  const next = iterator.next();

  if (next.done) {
    return tsplus_module_3.succeedNow(false, __tsplusTrace);
  }

  return tsplus_module_2.flatMap_(f(next.value), b => b ? tsplus_module_3.succeedNow(b, __tsplusTrace) : tsplus_module_4.suspendSucceed(() => loop(iterator, f, __tsplusTrace), __tsplusTrace), __tsplusTrace);
}
//# sourceMappingURL=exists.mjs.map