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

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

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

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

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