/** * Determines whether any element of the `Collection` satisfies the effectual * predicate `f`. * * @tsplus static effect/core/stm/STM.Ops exists */ export function exists( as: Collection, f: (a: A) => STM ): STM { return STM.suspend(loop(as[Symbol.iterator](), f)) } function loop( iterator: Iterator, f: (a: A) => STM ): STM { const next = iterator.next() if (next.done) { return STM.succeed(false) } return f(next.value).flatMap((b) => b ? STM.succeed(b) : STM.suspend(loop(iterator, f))) }