import * as tracing_1 from "../../../../Tracing";
const fileName_1 = "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/findM.ts";
import * as T from "../../../../Effect";
import * as O from "../../../../Option";
import { concreteId } from "../definition";
/**
 * Returns the first element that satisfies the effectful predicate.
 */

export function findM_(self, f) {
  return T.suspend(() => {
    const iterator = self.arrayLikeIterator();
    let next;

    const loop = (iterator, array, i, length) => {
      if (i < length) {
        const a = array[i];
        return T.chain_(f(a), r => r ? T.succeed(O.some(a), fileName_1 + ":26:24") : loop(iterator, array, i + 1, length), fileName_1 + ":25:24");
      } else if (!(next = iterator.next()).done) {
        return loop(iterator, next.value, 0, next.value.length);
      } else {
        return T.succeed(O.none, fileName_1 + ":31:25");
      }
    };

    next = iterator.next();

    if (!next.done) {
      return loop(iterator, next.value, 0, next.value.length);
    } else {
      return T.succeed(O.none, fileName_1 + ":40:23");
    }
  }, fileName_1 + ":13:19");
}
/**
 * Returns the first element that satisfies the effectful predicate.
 */

export function findM(f) {
  return self => findM_(self, f);
}
//# sourceMappingURL=findM.js.map